MATLAB: How to find first two largest peaks with sample location

two peaks

Please let me know, how to find its two highest peaks along with its samples information too.
P wave.JPG

Best Answer

d = rand(100,1); % assumed data
[vals,loc] = maxk(d,2); % first two peaks(mnaximum values) sample values and locations
plot(d); hold on; % plot original samples
plot(loc,vals,'rv', 'MarkerFaceColor', 'r'); % plot peak values