I have no idea why matlab does not understand this simple if function, any idea?

1 view (last 30 days)
Simply put, this if condition never gets satisfied. It does work for other ns like 0 0.2,1.6,2 etc but does not work for n==1.2. Is this a software bug? I am using Matlab R2012a
for n=0:0.2:2
if n==1.2
test1=1
end
end
Thanks

Accepted Answer

Walter Roberson
Walter Roberson on 24 Dec 2013
  1 Comment
Amirhossein
Amirhossein on 24 Dec 2013
Thanks Walter. I knew there was something deep going on here. I think the problem is that by default Matlab does not show the complete number. It is showing this to me: 1.200000000000000, so I thought that is the whole thing but I guess it is not.

Sign in to comment.

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!