Strange behaviour with elseif
Show older comments
Hi, I noticed something totally strange with a repeated elseif statement. Here is the code:
A = [0.0001:0.0001:0.0009];
for i=1:length(A)
x=A(i);
if x == 0.0001
x
elseif x == 0.0002
x
elseif x == 0.0003
x
elseif x == 0.0004
x
elseif x == 0.0005
x
elseif x == 0.0006
x
elseif x == 0.0007
x
elseif x == 0.0008
x
elseif x == 0.0009
x
else
display('Error')
end
end
When I run it, I get twice the "Error" displayed, for x=0.0003 and x=0.0008. I could reproduce it on two different Matlab version (R2009a & R2010a). Any idea? Thanks a lot.
Accepted Answer
More Answers (0)
Categories
Find more on Scope Variables and Generate Names in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!