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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Randall Ang
le 25 Mai 2020
Commenté : Alan Stevens
le 25 Mai 2020
for ii = 1:length(readings)
if readings(ii) > 100
break;
end
end
fprintf('First reading above 100 is at index %d.\n', ii);
1 commentaire
Réponse acceptée
Alan Stevens
le 25 Mai 2020
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);
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!