Getting indices of all unique rows

49 visualizaciones (últimos 30 días)
Andrew
Andrew el 3 de Dic. de 2012
I have a matrix "M" with 1,000 rows and 5 columns. The first column is the row number and columns 2:5 are ordinal numbers (-1, 0, 1). To get the number of unique rows with respect to columns 2:5 I've used the following:
uM = unique(M(:, 2:5));
But what I really want is the row indices for each unique row.
Let's say that M is really:
[1 0 1 1 -1; 2 1 0 -1 -1; 3 0 1 1 -1; 4 -1 0 -1 1 ]
I'd like to obtain a cell array vector that has:
{ (1, 3), 2, 4 }
Any ideas?
Thanks!

Respuesta aceptada

per isakson
per isakson el 3 de Dic. de 2012
Read the documentation on unique and note that there is a second and third output argument. Doc says:
[C,ia,ic] = unique(A,'rows')

Más respuestas (0)

Categorías

Más información sobre Logical 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