MATLAB: How to find the two tallest peaks in the data

findpeakshighestMATLABnpeakssignalsortstr

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?

Best Answer

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":