필터 지우기
필터 지우기

Addtion with 2x1 Vector and 2x3 Matrix

조회 수: 2 (최근 30일)
EM
EM 2017년 3월 21일
댓글: EM 2017년 3월 22일
Hi,
In the 2017a documentation, I find that you can "Create an array, A, and add a column vector to it. The vector is treated as though it is a matrix of the same size as A, so that each element in the vector is added to a row in A."
https://www.mathworks.com/help/matlab/ref/plus.html
I am using an older release of Matlab (2015a) and this operation does not work for me. I get the following error:
Error using + Matrix dimensions must agree.
Can anyone tell me how to perform this operation on an older release, and exactly which release was this new functionality available?
Thanks

채택된 답변

Jan
Jan 2017년 3월 21일
편집: Jan 2017년 3월 21일
The new method was introduced in R2016b. See e.g. Loren: arithmetic-expanding. Use bsxfun for older Matlab versions:
A = rand(2, 3)
b = rand(2, 1)
R1 = bsxfun(@plus, A, b) % Matlab < 2016b
R2 = A + b % Matlab >= 2016b
bsxfun was introduced in 2007a. Before the array way expaned by repmat or ones:
R3 = A + b(:, ones(1, 3))
R4 = A + repmat(b, [1, 3])
The ones-method was processed efficiently by Matlab's JIT acceleration: The timings looked like Matlab does not waste time with creating the expanded array explicitely, but the addition was performed directly. But this is an assumption only: The JIT was never documented exactly.
  댓글 수: 6
Steven Lord
Steven Lord 2017년 3월 21일
In the section for release R2016b it's the first item in the Mathematics subsection. It's called implicit expansion.
EM
EM 2017년 3월 22일
Thanks for all the help guys! Much appreciated!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by