Getting indices of all unique rows

44 ビュー (過去 30 日間)
Andrew
Andrew 2012 年 12 月 3 日
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!

採用された回答

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by