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!