MATLAB: Error in findpeaks when saving values

findpeaks

I am trying to find the peaks of a 2D array using the find peaks function. I noticed however that when i request any other value than 3 for the number of peaks I obtain a subscripted assignment dimension mismatch error. The for loop code is shown below
for i = 1 : count
[ peak(i,:), location(i,:) ] = findpeaks( low_time_signal(i,:), 'NPEAKS', 3);
end
The variable count is equivalent to the number of rows in low_time_signal.

Best Answer

NPEAKS is the maximum number of peaks, not a guarantee that it will find that many peaks.
And of course how you initialized the arrays makes a difference; if you initialized to smaller than the number of peaks you specify then you will have a problem.