Filter löschen
Filter löschen

Getting indices of all unique rows

23 Ansichten (letzte 30 Tage)
Andrew
Andrew am 3 Dez. 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!

Akzeptierte Antwort

per isakson
per isakson am 3 Dez. 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')

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by