# How to replace a column vector in matrix

509 views (last 30 days)
Danny Maefengea on 28 Aug 2020
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?
##### 2 CommentsShowHide 1 older comment
kelly lim on 3 Dec 2021
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 on 28 Aug 2020
A = [1 -4 1;4 -1 2;2 2 -3]
B = [6;-1;-20]
B=B'
A(1,:)=B'
Phuwanut Pataratawinun on 6 Mar 2022
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'

### Categories

Find more on Matrices and Arrays in Help Center and File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by