For-if loop not working?

조회 수: 12 (최근 30일)
Catherine Mohs
Catherine Mohs 2019년 2월 15일
답변: Star Strider 2019년 2월 15일
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
Kevin Phung
Kevin Phung 2019년 2월 15일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2019년 2월 15일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by