Removing duplicates of rows from a matrix (finding and removing combination duplicates)
조회 수: 5 (최근 30일)
이전 댓글 표시
I have a 12x3 double matrix and I want to identify duplicates of combinations of the same numbers and then produce a matrix containing the rows minus those duplicates (e.g. remove 2 as it is a duplicate of combo 1).

How can I go about this?
댓글 수: 0
채택된 답변
Walter Roberson
2021년 3월 13일
[~, ia] = unique(sort(YourMatrix, 2),'rows', 'stable');
NewMatrix = YourMatrix(ia,:);
Although the sort() changes the order of the columns, I go back to the original for the indexing. So for example if the first row had been [5 3 4] then the first row of output would be [5 3 4]... just in case that was important to you.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!