MATLAB: Finding prominent maxima and minima of a column vector

prominent max min

Hello,
Suppose I Have a column vector wcich has multiple maxima and minima, I just want to find the index of N= 4 number of them ( prominent maxia and minima).
And if I use something like 'findpeak' then it gives a lots of local max and min as for a noisy signal. I want to get the prominant max & min indices of the 2nd colm of the attachment please.
Thank you

Best Answer

Although findpeaks needs some help here, it can find all four:
[D,S] = xlsread('ab1.xlsx');
[pks,plocs] = findpeaks([D(:,2); min(D(:,2))], 'MinPeakProminence',1); % Append ‘0’ To Far End To Identify Last Peak
[vls,vlocs] = findpeaks(-D(:,2), 'MinPeakProminence',1)
figure
plot(D(:,1), D(:,2))
hold on
plot(D(plocs,1), pks, '^r')
plot(D(vlocs,1), vls, 'vr')
hold off
grid
legend('Data','Peaks','Valleys')
The associated times are: D(plocs,1).
pks =
1.2000
1.2001
1.2001
1.2000
locs =
3165
4072
4675
5138
Similarly for the valleys:
vls =
1.0e-04 *
-0.0140
0.3678
0.5941
-0.1694
vlocs =
2708
3753
4446
4954