Problem with equating for loop index to a variable.
Afficher commentaires plus anciens
I run the following code and it does not produce the expected results:
% code
clear all
FlowRate=0.6;
for ThermalImpCurve = 0.2:0.2:1.6
if FlowRate==ThermalImpCurve
ThermalImpCurve
break;
end
end
if the variable FlowRate is 0.6 or 1.4 the loop does not break.
1 commentaire
Stephen23
le 13 Mai 2016
Welcome to the world of floating point number calculations!. This is such a common topic that the wiki has an explanation of it too:
There are hundreds of threads asking the same question (with the same answer)
and finally:
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!