1D matrix addition weirdness

1 Ansicht (letzte 30 Tage)
Alex Pedcenko
Alex Pedcenko am 17 Jan. 2019
Bearbeitet: Stephen23 am 17 Jan. 2019
>> ones(5,1)+ones(1,5)
ans =
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
% what?????
% but
>> ones(2,5)+ones(5,2)
Matrix dimensions must agree.
% as expected
% 2014 ver produce error in both cases
Why is this unexpected vecor addition behaviour in recent MATLABs (2017,2018)??????

Akzeptierte Antwort

madhan ravi
madhan ravi am 17 Jan. 2019
Bearbeitet: madhan ravi am 17 Jan. 2019
  3 Kommentare
madhan ravi
madhan ravi am 17 Jan. 2019
Anytime :)
Stephen23
Stephen23 am 17 Jan. 2019
Bearbeitet: Stephen23 am 17 Jan. 2019
"its still weird from mathematics point of view [wrong actually])"
Note that implicit expansion is really just an extension of scalar expansion, which has been part of MATLAB for a very long time: is scalar expansion weird/wrong as well?? A strict language would require all operations to be performed only on exactly compatible array sizes (i.e. the same size for array operations), but not only would this be inconvenient, using repmat all the time would likely be much less efficient than scalar expansion and implicit expansion.
It would certainly be nice if it was possible to select expansion or no expansion.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Computational Geometry finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by