MATLAB: For-if loop not working

MATLABmatrixmaximum

A=[2 5 4 13 4 23 8 3 9 5 0];
for k=1;length(A)
[Maxima,MaxIdx]=findpeaks(A)
if Maxima>10
Maxima=Maxima(k)
end
end
Maxima
It should display…
Maxima= 13 23
However, it is displaying…
Maxima= 5 13 23 9
What am I doing wrong?

Best Answer

Lose the loop!
Try this:
A=[2 5 4 13 4 23 8 3 9 5 0];
[Maxima,MaxIdx]=findpeaks(A)
Maximav = Maxima(Maxima > 10);
Maximav
produces:
Maximav =
13 23