how to substitute a row vector to a column of a matrix
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Jos (10584)
2014-6-12
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
2 个评论
Samuel Akpobome
2018-1-25
You can do this as follows;
c(:,2:3)=[b(:) b(:)] %this substitutes b(as a column matrix) into columns 2 and 3 (or 2 to 3) in the matrix c
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!