How to eliminate duplicate rows without sorting column in Matlab
이전 댓글 표시
Hi,
Here is one problem that maybe some people will find useful to them.
I got matrix, lets say 500x9. In this matrix some rows are identical so they have to be eliminated. But the 3rd column musn't be sorted. This must be unchanged. All other columns can be changed (sorted).
I tryed this with function unique, but it sort me 3rd column.
Thank you in advance.
Have a nice day,
Nejc
답변 (1개)
Azzi Abdelmalek
2013년 4월 4일
unique(A,'stable')
댓글 수: 4
Nejc
2013년 4월 4일
Azzi Abdelmalek
2013년 4월 4일
편집: Azzi Abdelmalek
2013년 4월 4일
A=[1 2;3 5;1 2;0 2;0 2]
[~,idx]=unique(A,'rows')
out=A(sort(idx),:)
Sean de Wolski
2013년 4월 4일
@Nejc, the 'stable' option became available in R2012a.
Azzi Abdelmalek
2013년 4월 4일
Edit
A=[1 2;3 5;1 2;0 2;0 2]
[~,idx]=unique(A,'rows','first')
out=A(sort(idx),:)
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!