Remove rows in a matrix not having same element

조회 수: 3 (최근 30일)
subhashree priyadarshini
subhashree priyadarshini 2020년 10월 2일
댓글: subhashree priyadarshini 2020년 10월 2일
I am having a matrix
A =[1 2 3;
1 2 6;
1 2 7;
1 3 6;
1 3 7;
1 6 7;
2 3 6;
2 3 7;
2 6 7;
3 6 7]
I need the rows having element 2 means final matrix should be
A =[1 2 3;
1 2 6;
1 2 7;
2 3 6;
2 3 7;
2 6 7]

채택된 답변

Mario Malic
Mario Malic 2020년 10월 2일
This should work
Loc = ismember(A, 2)
idx = any(Loc,2)
B = A(idx, :)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by