MATLAB: How to substitute a row vector to a column of a matrix

columnmatrixrow vectorsubstitute

Hi, I have
a=[1 2 3 4;
5 6 7 8;
9 10 3 4]
b=[4 5 7]
I want to substitute b to my second column of a to become
c=[1 4 3 4;
5 5 7 8;
9 7 3 4]
what can I do?
Thanks.

Best Answer

a = [1 2 3 4;
5 6 7 8;
9 10 3 4]
b = [4 5 7]
c = a % copy a
c(:,2) = b(:) % transform b into a column vector and replace the 2nd column of c with it