Extract Common and Uncommon Matrix with Row Repetition

조회 수: 2 (최근 30일)
Mukund
Mukund 2018년 3월 24일
댓글: Stephen23 2018년 3월 24일
I want to segregate common and uncommon matrix with row Repetition. Current matlab commands ismember and setdiff do it by removing repeated rows.
A=[2 3 4;4 1 2;3 5 7;2 8 1;2 3 4;5 5 5;4 1 2;4 1 2; 5 5 5]
B=[2 3 4;4 1 2;2 8 1]
c=ismember(B,A,'rows')
C=A(c,:)
D=setdiff(A,B,'rows')
C=[2 3 4;4 1 2;3 5 7] % Not the expected ans
D=[3 5 7; 5 5 5] %Not the expected ans (because no rows repetition).
I want the output with rows repetition. Expected output is
C=[2 3 4;4 1 2;2 8 1;2 3 4;4 1 2;4 1 2] % Common Matrix
D=[3 5 7;2 8 1;5 5 5; 5 5 5]% Uncommon matrix.
How it could be done?

채택된 답변

Birdman
Birdman 2018년 3월 24일
c=ismember(A,B,'rows')
C=A(c,:)
D=A(~c,:)
Note that
2 8 1
row is both located at A and B matrices, therefore your D matrix should look like
D=[3 5 7;5 5 5; 5 5 5]
  댓글 수: 1
Stephen23
Stephen23 2018년 3월 24일
@mukind: What would you hope to change? ismember already returns an index that does exactly what you want. And by the very definition of sets setdiff does not return duplicates.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by