How to find rows with multiple entries that are equal?
이전 댓글 표시
I have a NxM matrix and I want to find the rows that have M-1 duplicate entries. For example:
A=[1 1 2 4;
2 2 2 1;
2 9 3 0;
3 0 3 3;
4 3 2 2];
fun(A);
ans = [2 2 2 1;
3 0 3 3]
How could I do this, preferably elegantly in a few lines? I am trying to avoid loops because I anticipate working with large matrices eventually.
채택된 답변
추가 답변 (2개)
the cyclist
2015년 10월 6일
편집: the cyclist
2015년 10월 6일
A(sum(diff([nan(size(A,1),1),sort(A,2)],1,2)==0,2)==(size(A,2)-2),:)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!