Create array of values returned from inside an if statement.
이전 댓글 표시
Here is sample code for what I am trying to achieve. This loop correctly returns the values I want (where the value is larger than the previous and subsequent values). Thus, it returns 4, 5, and 9 correctly. However, I want ex_vals to be an array of these values (ex_vals = [4,5,9]) but this code just returns and overwrites ex_vals each time. This seems simple but I have not used Matlab in a while. Any help is appreciated.
ex = [1,2,3,4,3,4,5,4,5,6,7,8,9,7];
for i = 2:length(ex)-1
if ex(i) > ex(i-1) & ex(i) > ex(i+1)
ex_vals = ex(i)
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!