Matlab R2016b comes with a̶ ̶n̶e̶w̶ ̶f̶e̶a̶t̶u̶r̶e̶ a monster that will kill us all: Operator implicit expansion.
Basically if you have a matrix A and a vector B, you can now just do A+B (without bsxfun
or repmat
). Sounds great right?
However if you provide a column vector and a row vector it also works!!
Example:
a = 1:4 % row vector
b = (1:4)' % column vector
% before R2016b:
a + b
Matrix dimensions must agree.
% after R2016b:
a + b
ans =
2 3 4 5
3 4 5 6
4 5 6 7
5 6 7 8
Expands both vectors and gives a Matrix as result!! This is very bad, since you might be doing completely undesired operations without noticing.
So my question is: Is there a way of disabling implicit expansion and giving back a Matrix dimensions must agree
error?