MATLAB: Logical -1 = Logical 1

logical(-1)true

Dear all, While reviewing a code I found the following expression:
assert(fid ~= -1, etc
By checking the logical operators I found that for a true condition the number is 1.
I would like to ask if in Matlab applies the same rule than for other packages where any non-zero value is true.
Thanks,
Diego

Best Answer

Yes:
logical([-1 0 1 20 -10 .001 eps ])
The exception is NaN. NaN is non-zero, yet cannot be converted to logical. Try to do it and see what you get!