how to find peaks

21 views (last 30 days)
David
David on 2 Nov 2023
Answered: Dyuman Joshi on 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)

Accepted Answer

Dyuman Joshi
Dyuman Joshi on 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])

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!