Eliminate a row where a column has repeated values

1 回表示 (過去 30 日間)
Hansel Montuffar
Hansel Montuffar 2016 年 6 月 3 日
回答済み: Andrei Bobrov 2016 年 6 月 3 日
Hi I have the following matrix
eliti =
Columns 1 through 8
0 0 1.0000 0 0 0 0 0
0 0 1.0000 0 0 0 0 0
0 1.0000 0 1.0000 1.0000 0 0 0
Columns 9 through 16
0 0 0 0 0 1.0000 1.0000 0
1.0000 1.0000 0 0 0 0 1.0000 0
0 0 0 0 0 0 1.0000 0
Columns 17 through 21
-24.0000 38.0000 10.0751 0.0413 0.2388
-52.0000 26.0000 11.1629 0.0458 0.6012
-24.0000 38.0000 10.0751 0.0413 0.3106
And I need to eliminate where there a repeated values in the 18th column so it will be like this eliti =
Columns 1 through 8
0 0 1.0000 0 0 0 0 0
0 1.0000 0 1.0000 1.0000 0 0 0
Columns 9 through 16
1.0000 1.0000 0 0 0 0 1.0000 0
0 0 0 0 0 0 1.0000 0
Columns 17 through 21
-24.0000 38.0000 10.0751 0.0413 0.2388
-52.0000 26.0000 11.1629 0.0458 0.6012

採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 6 月 3 日
[~,b] = unique(eliti(:,18),'stable');
eliti_new = eliti(b,:);

その他の回答 (1 件)

Chad Greene
Chad Greene 2016 年 6 月 3 日
You can use the indices returned by unique to get the rows corresponding to unique values in column 18:
M = randi(5,[3 21])
[~,ia] = unique(M(:,18))
M_new = M(ia,:);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by