필터 지우기
필터 지우기

How do I add column vector to a matrix ? Documentation examples does not work.

조회 수: 30 (최근 30일)
I copied this example directly from the documentation and it returns error "Matrix dimensions must agree". What is going on? A = [1 2 3; 4 5 6] A =
1 2 3
4 5 6
b = [10; 100] b =
10
100
A + b ans =
11 12 13
104 105 106

채택된 답변

Steven Lord
Steven Lord 2016년 11월 30일
Implicit expansion was added as a feature in MATLAB in release R2016b. You're using an older release, one in which you would have to use the bsxfun function to explicitly ask for the same expansion behavior for vectors and matrices.

추가 답변 (1개)

dbmn
dbmn 2016년 11월 30일
hi,
this works like this
A=[A, b]
  댓글 수: 2
norcalpedaler
norcalpedaler 2016년 11월 30일
Please re-read my OP. I want to compute the sum column by column.
dbmn
dbmn 2016년 11월 30일
Sorry, i understood that the wrong way.
I might still not fully understand it. Can you give an example of how the output should look like?
Something like this?
sum(A+b)
ans =
115 117 119
Or this?
cumsum(A+b)
ans =
11 12 13
115 117 119
Or this?
cumsum(sum(A+b))
ans =
115 232 351

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

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by