For-if loop not working?
조회 수: 12 (최근 30일)
이전 댓글 표시
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
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
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!