Returning an Entire Row Based on the Max in a Column

1 view (last 30 days)
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.

Accepted Answer

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

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!