Problem with equating for loop index to a variable.
Show older comments
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 Comment
Stephen23
on 13 May 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:
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!