For-if loop not working?
2 次查看(过去 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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!