For-if loop not working?

11 views (last 30 days)
Catherine Mohs
Catherine Mohs on 15 Feb 2019
Answered: Star Strider on 15 Feb 2019
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?
  1 Comment
Kevin Phung
Kevin Phung on 15 Feb 2019
what are you trying to do with your forloop?
findpeaks(A) alone should just return 5 13 23 9, as expected.
A local peak is a data sample that is either larger than its two neighboring samples or is equal to Inf. Non-Inf signal endpoints are excluded. If a peak is flat, the function returns only the point with the lowest index.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 15 Feb 2019
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

More Answers (0)

Products


Release

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!