I was just curious why Matlab can compare an empty matrix to a singleton matrix. In particular
>> [] == [1]
ans =
[]
It just seems odd that it would do that and I’m just wondering why it would do that. This also works for other comparison operations (<=, <, >=, >, !=). It gives an error if the size of the row or column is greater than one.
Thanks!
Edit: I also believe they do this for other operators, such as addition, subtraction, etc.
[](empty matrix) is considered a valid matrix representation of size0x0by MATLAB. From the documentation for theeqfunction, which is what gets called when you use operator==to compare matrices, the behavior is as follows:In the comparison
[] == [1], the left operand is non-scalar (isscalar([])returns0) while the right operand is scalar. So scalar expansion rules apply, and the scalar operand is expanded to the dimensions of the non-scalar operand (in this case0x0), and the result is an empty matrix.