finding unique rows with largest value in 3rd column
古いコメントを表示
Suppose I have a matrix
A=
1 2 3
1 3 8
2 1 3
2 1 5
2 2 8
1 2 9
4 3 2
I want to find a matrix which has unique first column and largest 3rd column.. So my resultant matrix should be
1 2 9
2 2 8
4 3 2
Any help will be highly appreciated!
2 件のコメント
Sean de Wolski
2013 年 12 月 19 日
So the order of the first two columns doesn't matter?
Mahi Nazir
2013 年 12 月 19 日
採用された回答
その他の回答 (1 件)
Muhammet Bozkaya
2017 年 11 月 20 日
編集済み: Muhammet Bozkaya
2017 年 11 月 20 日
Simple answer for this case.
First sort rows with ascending 1st column and descending 3rd column(column you want to get the max), then see take unique...
A=[1 2 3
1 3 8
2 1 3
2 1 5
2 2 8
1 2 9
4 3 2];
A=sortrows(A,[1 -3]);
[~,idx]=unique(A(:,1));
A=A(idx,:);
result: 1 2 9
2 2 8
4 3 2
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!