Im getting a really weird result using ==
in MATLAB_R2009b on OS X. Example from the prompt:
s =
2
>> class(s)
ans =
double
>> class(s) == 'double'
ans =
1 1 1 1 1 1
Six times yes? Can anyone explain this || offer a solution?
In Matlab, strings are really just arrays of characters. So what you're really doing is comparing two arrays. This does an element-wise compare, i.e. character-by-character. So you could do:
all(class(s) == 'double')
but that would give a run-time error if the string length of class(s)
was not 6. Much safer would be to do:
strcmp(class(s), 'double')
But what you should really be doing is:
isa(s, 'double')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With