Getting indices of all unique rows

48 vues (au cours des 30 derniers jours)
Andrew
Andrew le 3 Déc 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!

Réponse acceptée

per isakson
per isakson le 3 Déc 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')

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by