Problem with equating for loop index to a variable.
Mostrar comentarios más antiguos
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 comentario
Stephen23
el 13 de Mayo de 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:
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!