how mark the highest maximums of a graph?

5 views (last 30 days)
hello, I try to mark the highest maximums of a graph that I make using data from an excel. but I can't.
the code i use is this:
% Representación Gráfica
xlabel("tiempo"), ylabel("nivel")
grid on
I get an error with the select function and I don't know what to do

Accepted Answer

Steven Lord
Steven Lord on 10 Mar 2022
Let's plot some sample data.
x = 0:360;
y = sind(x).*(x-60).*(x-180).*(x-210)/(360.^2);
plot(x, y)
hold on
Identify the local maxima and plot a second "line" highlighting them with circles.
L = islocalmax(y);
plot(x(L), y(L), 'o')
Bjorn Gustavsson
Bjorn Gustavsson on 10 Mar 2022
You're latest request becomes a very messy task. For that I would definitely write a function. Because now you have to handle selection of maxima in a "not at all obvious manner" what about high peaks that are way above the threshold but a bit close in x, how to handle a slightly lower peak that is just outside the x-separation to the highest peak but within that x-separation to a sub-peak close to the highest one, should that third peak be included or excluded. This is too much hassle to just toss something together on a whim without rather careful and precise specifications.

Sign in to comment.

More Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 10 Mar 2022
You might get something from a simple solution like this (if your curve is not too noisy):
[m_al_max,idx_max] = max(m_al);
hold on

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!