For-if loop not working?

12 visualizzazioni (ultimi 30 giorni)
Catherine Mohs
Catherine Mohs il 15 Feb 2019
Risposto: Star Strider il 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 Commento
Kevin Phung
Kevin Phung il 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.

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 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

Più risposte (0)

Prodotti


Release

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by