Hi everyone, I have been trying to debug this for loop as it always retain the last value of the array even if none of the conditions meet for every element. For instance, using readings = [1 20 55 90], it will print that reading(4)>100.
1 回表示 (過去 30 日間)
古いコメントを表示
for ii = 1:length(readings)
if readings(ii) > 100
break;
end
end
fprintf('First reading above 100 is at index %d.\n', ii);
採用された回答
Alan Stevens
2020 年 5 月 25 日
Try:
ix = 0;
for ii = 1:length(readings)
if readings(ii) > 100
ix = ii;
break;
end
end
fprintf('First reading above 100 is at index %d.\n', ix);
その他の回答 (0 件)
参考
カテゴリ
Help Center および 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!