A = [1 -4 1;4 -1 2;2 2 -3]
B = [6;-1;-20]
I want to replace part of matrx A i.e (1 -4 1) with B.
How can I do this?
Thank you for your help.

댓글 수: 2

"How can I do this? "
Basic indexing (just the the introductory tutorials show):
>> A = [1,-4,1;4,-1,2;2,2,-3]
A =
1 -4 1
4 -1 2
2 2 -3
>> B = [6;-1;-20];
>> A(1,:) = B
A =
6 -1 -20
4 -1 2
2 2 -3
kelly lim
kelly lim 2021년 12월 3일
how do you set the name of the new matrix , instead of A can you change it to Ax without changing the name of the original matrix. Please demosntrate thank you

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

 채택된 답변

Sara Boznik
Sara Boznik 2020년 8월 28일

0 개 추천

A = [1 -4 1;4 -1 2;2 2 -3]
B = [6;-1;-20]
B=B'
A(1,:)=B'

댓글 수: 4

James Tursa
James Tursa 2020년 8월 28일
편집: James Tursa 2020년 8월 28일
You don't actually need to do any transposing. Just using B directly works, even though B is a column vector and you are assigning it to a row:
A(1,:) = B;
Danny Maefengea
Danny Maefengea 2020년 8월 28일
Thank you Sir
kelly lim
kelly lim 2021년 12월 3일
how do you set the name of the new matrix , instead of A can you change it to Ax without changing the name of the original matrix. Please demosntrate thank you
If you want changed matrix Ax without changing matrix A, just copy the contents of matrix A over to a new matrix Ax, then do the same replacement.
A = [1 -4 1;4 -1 2;2 2 -3]
B = [6;-1;-20]
B = B'
Ax = A
Ax(1,:) = B'

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품

릴리스

R2020a

태그

Community Treasure Hunt

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

Start Hunting!

Translated by