I am using findpeaks to determine the local minima and maxima in a given input signal. I am then calculating the peak-to-peak difference between each of these minima/maxima pairs throughout the entire signal. Shown is my current code:
signal = myvector;[pksmax,locsmax] = findpeaks(signal);[pksmin,locsmin] = findpeaks(-signal); realpksmin = -1*pksmin;for j = 1:size(realpksmin) pk2pkmaxmin(j) = abs(pksmax(j) - realpksmin(j));end
Most of the time,
size(pksmax) == size(pksmin)
Sometimes these two vectors differ in size very slightly. If the above statement is false, then I have an error in my loop,
Index exceeds the number of array elements (154).
How can I ensure that
size(pksmax) == size(pksmin)
is always true upon using findpeaks(signal)?
Best Answer