How do I get the maximum value for x with its corresponding y value?

I have 2 columns of numbers. I want to find the maximum value of the numbers in the x column and it's corresponding y value. I am not sure how to put in the code. please help

 Accepted Answer

Example
A=[1 2;3 4;47 20;5 55]
[xmax,idx]=max(A(:,1));
ymax=A(idx,2)

3 Comments

Don't really understand where your going with that. I tried using that in Matlab and its giving me an error msg. I only want to get the maximum value in the column 1 and the value of column 2 that is in the same row as the maximum value of column 1. So in your example I want matlab to get me 47, 20. How do I put in that code.
Thanks for the quick answer
That's what my code do
A=[1 2;3 4;47 20;5 55];
[xmax,idx]=max(A(:,1));
ymax=A(idx,2);
xmax
ymax
% the result
xmax =
47
ymax =
20
Thanks, original code wasn't working

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!