How do I find the two tallest peaks in my data?

20 views (last 30 days)
I load in my data and plot it as follows:
load sunspot.dat
year = sunspot(:,1);
relNums = sunspot(:,2);
How do I find just the two tallest peaks?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Nov 2019
To find the two shortest peaks, use the "findpeaks" function with the "SortStr" property set to descending order and "NPeaks" set to 2:
[pks,loc] = findpeaks(relNums, year, 'SortStr', 'descend', 'NPeaks', 2);
Here is the documentation for "findpeaks":

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!