Returning an Entire Row Based on the Max in a Column

1 Ansicht (letzte 30 Tage)
Erick Sirois
Erick Sirois am 27 Jan. 2020
Kommentiert: Erick Sirois am 27 Jan. 2020
Hi.
I'm trying to get the entire row based on the max value of a column. For example:
x = [5 6 6 9
7 3 2 4
3 12 8 4]
Now say I want the entire row belonging to the column 2 maximum value. I should get the row with 3 12 8 4 because 12 is the max value in column 2.
Is there a way to do this? I've tried the help and searching here and other places but cant seem to find it.

Akzeptierte Antwort

Matt J
Matt J am 27 Jan. 2020
[~,imax]=max(x(:,2));
out = x(imax,:)

Weitere Antworten (0)

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by