How to eliminate duplicate rows without sorting column in Matlab

5 visualizaciones (últimos 30 días)
Nejc
Nejc el 4 de Abr. de 2013
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

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 4 de Abr. de 2013
unique(A,'stable')
  4 comentarios
Sean de Wolski
Sean de Wolski el 4 de Abr. de 2013
@Nejc, the 'stable' option became available in R2012a.
Azzi Abdelmalek
Azzi Abdelmalek el 4 de Abr. de 2013
Edit
A=[1 2;3 5;1 2;0 2;0 2]
[~,idx]=unique(A,'rows','first')
out=A(sort(idx),:)

Iniciar sesión para comentar.

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by