how to find peaks

18 visualizzazioni (ultimi 30 giorni)
David
David il 2 Nov 2023
Risposto: Dyuman Joshi il 2 Nov 2023
I want to find peaks from a plot, but I won't to use "findpeaks".
my professor told me to create a treshold in certain point and then count the peak as a region with "imfill".
I still didn't know ho to execute that, can someone give me some advice.
Here is an example code:
x=linspace(1,10);
y=sin(2*x);
plot(x,y)

Risposta accettata

Dyuman Joshi
Dyuman Joshi il 2 Nov 2023
I don't see how imfill would work with curves and plots (unless saved as an image, of course).
findpeaks finds the local maxima.
So, a simple workaround is to use islocalmax paired with logical indexing -
x=linspace(1,10);
y=sin(2*x);
idx = islocalmax(y);
plot(x,y)
hold on
plot(x(idx), y(idx), '*', 'MarkerSize', 10)
legend({'function', 'peaks'})
ylim([-1.2 1.2])

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by