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:
but that would give a run-time error if the string length of
class(s)was not 6. Much safer would be to do:But what you should really be doing is: