Plot x values corresponding to n max y values in a table

I have excel data imported as a table and want to display 5 max y values and then plot them against their corresponding x value. i am unable to get matlab to find the corresponding x values.

 Accepted Answer

Matt J
Matt J on 11 Jul 2021
Edited: Matt J on 11 Jul 2021
i am unable to get matlab to find the corresponding x values.
It's unclear how you've been approaching it, but if you are using the the maxk() function, calling it with two output arguments should give you both the y-values and the x-values (or at least their row indices) pretty straightforwardly.

3 Comments

Hi,
Table = xlsread('newfile.xlsx','Sheet1');
x = Table(:,1);
y = Table(:,2);
B = maxk(y,10)
This is how I was approaching it. What do you mean by two output arguments?
[ymax, rowmax] = maxk(y,10);
xmax=x(rowmax)

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!