Clear Filters
Clear Filters

Getting indices of all unique rows

23 views (last 30 days)
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!

Accepted Answer

per isakson
per isakson on 3 Dec 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')

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!