How to find maximal values in matrix?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Tien Tran
am 10 Apr. 2016
Beantwortet: Star Strider
am 10 Apr. 2016
- I have a matrix: A =[1, 128; 2, 300; ...;20, 500;...;99, 10; 100, 0];
- the row I need to extract be B=[20,500], with 500 is maximal value of 2sd colum.
How I can do?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 10 Apr. 2016
This works:
A =[1, 128; 2, 300;20, 500;99, 10; 100, 0];
B = A(A(:,2) == max(A(:,2)),:)
B =
20 500
It compares the second column of ‘A’ with the maximum of the second column of ‘A’, and then selects that entire row.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu NaNs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!