finding unique rows with largest value in 3rd column
Ältere Kommentare anzeigen
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 Kommentare
Sean de Wolski
am 19 Dez. 2013
So the order of the first two columns doesn't matter?
Mahi Nazir
am 19 Dez. 2013
Akzeptierte Antwort
Weitere Antworten (1)
Muhammet Bozkaya
am 20 Nov. 2017
Bearbeitet: Muhammet Bozkaya
am 20 Nov. 2017
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
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!