1D matrix addition weirdness

조회 수: 1 (최근 30일)
Alex Pedcenko
Alex Pedcenko 2019년 1월 17일
편집: Stephen23 2019년 1월 17일
>> 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)??????

채택된 답변

madhan ravi
madhan ravi 2019년 1월 17일
편집: madhan ravi 2019년 1월 17일
  댓글 수: 3
madhan ravi
madhan ravi 2019년 1월 17일
Anytime :)
Stephen23
Stephen23 2019년 1월 17일
편집: Stephen23 2019년 1월 17일
"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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Computational Geometry에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by