Why doesn't [] ~=1 yield logical one?
Show older comments
I'm using matlab r2012B, because the computer is old and disconnected from internet and it runs my experiment and is not to be updated.
I have the following:
a = [];
if a ~= 1
disp('a~=1')
end
Now i ask myself, will the message 'a~=1' be printed? the answer is obviously yes. Why? because the expression 'a~=1' is clearly True. It is True that [] is not equal to 1. one is the number 1, and the other, is NOT the number 1. If I
If this threw an error, I would accept that. That seems reasonable.
Therefore, there must be some reason that this doesn't behave like I expect. What is that reason? Why does it behave the same way for a = 'string' (which evaluates to 0, makes sense) or a = {} (which throws an error, also reasonable).
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!