Recently, in R2016b a feature was added to MATLAB, which is causing a lot of headaches in the school where I teach.
Nowadays formulae, which traditionally would be considered illegal or at least shady maths are executed successfully:
[1, 2] + [3, 4]' -> [4, 5; 5, 6]
[1, 2]' + [3, 4, 5] -> [4, 5, 6; 5, 6, 7]
So adding a row vector to a column vector is treated as an addition of two matrices one can get from repeating the vectors up to the "suitable" dimensions. In older versions this would have produced an error message informing that the addition of matrices with different dimensions is not possible.
I think asking why is a bit broad, although if you do know why, I'd love to know. Instead I will ask, is there a way to disable this functionality? To novice programmers this is a world of hurt when the conventional mathematics doesn't seem to be in line and the resulting matrix often goes unnoticed causing errors only later on.
I can not see this being a useful part of MATLAB syntax and behavior, as it requires too much interpretation, reading into the intention of the programmer. repmat
is there for a reason, and a dedicated function could be introduced to accommodate for the need of this thing.