필터 지우기
필터 지우기

How do I sum a vector (row) to a matrix?

조회 수: 3 (최근 30일)
JOSUE PÁNCHEZ
JOSUE PÁNCHEZ 2021년 11월 16일
댓글: Star Strider 2021년 11월 16일
If I have
A=[1 0 0 1;
-1 0 1 1;
1 1 1 1]
B=[1 2 2 1]
How do I add the vector B to the 1st row of A so I get:
A=[2 2 2 3;
-1 0 1 1;
1 1 1 1]

채택된 답변

Star Strider
Star Strider 2021년 11월 16일
This involves a bit of indexing.
Note that the rest of ‘A’ is unchnaged, and onlly ‘A(1,:)’ is involved in the operation.
A=[1 0 0 1;
-1 0 1 1;
1 1 1 1];
B=[1 2 2 1];
A(1,:) = A(1,:) + B
A = 3×4
2 2 2 2 -1 0 1 1 1 1 1 1
.
  댓글 수: 2
JOSUE PÁNCHEZ
JOSUE PÁNCHEZ 2021년 11월 16일
Thank you so much!!!!
Star Strider
Star Strider 2021년 11월 16일
As always, my pleasure!
.

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

추가 답변 (1개)

the cyclist
the cyclist 2021년 11월 16일
편집: the cyclist 2021년 11월 16일
A=[1 0 0 1;
-1 0 1 1;
1 1 1 1];
B=[1 2 2 1];
A(1,:) = A(1,: ) + B
A = 3×4
2 2 2 2 -1 0 1 1 1 1 1 1

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by