If I evaluate this expression:
3 + + 2
or also
3 + + + + + + 2
I obtain 5
as the result.
If I also insert the -
operator I also obtain a result (1
in this case):
3 + - + - + - 2
I was thinking that the space between operators can be considered as zero, but if I use the times operator, I instead obtain an error:
3 * * 2 % Error: Unexpected MATLAB operator.
What's happening? What's the meaning of this syntax and why does it work with +
and -
but not with *
?
Why this is valid syntax?
I'm using Matlab R2014a.
+
and -
can be binary or unary operators. *
Can only be binary.
In your code, all +
and -
symbols after the first are probably being parsed as unary operators. So 3 + - 2
is interpreted as 3 + (-2)
(the +
is binary, the -
is unary). Similarly, 3 - + - 2
is interpreted as 3 - (+-2)
, that is, 3 - (-2)
.
That doesn't work with *
because it cannot be a unary operator.
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