I'm trying to find the local maxima of a data set using the findpeaks()
function and so far I have this code:
[pks, locs] = findpeaks(signal);
max_times = zeros(size(locs));
if n = 1:size(locs);
max_times(n) = (times(locs(n)));
end
What am I trying to do? Well I have a set of signal data and the corresponding times. I want to get the local maxima values and output two vectors; the maxima signal values and the times that they occured.
How am I doing it? I'm using the findpeaks function to find the peaks (pks) and location (locs) of the maxima. I'm then setting up a blank array the same length as the locs vector and then using an if loop to fill up the empty max_times(n) vector with the times that the maxima occur
The problem? I keep getting this errorExpression or statement is incomplete or incorrect.
about my if loop. I don't understand what this means/ how do I solve this problem/ edit my code to get it to do what I want?
Thanks for any help!
What you are thinking is totally wrong.
If
is not a loop its a conditional statement
what you want here is a for
loop
for n = 1:size(locs)
% your code
end
also times
take two parameter and you should figure it out yourself what it should be