如何在Matlab中将向量添加到矩阵中? [英] how can I add a vector to a matrix in matlab?
本文介绍了如何在Matlab中将向量添加到矩阵中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过将向量的i索引添加到i行中的所有成员的方式,如何将向量添加到Matlab中的矩阵?
How can I add a vector to a matrix in Matlab, in a manner that the i's index of the vector would be added to all the members in the i's row?
例如:
A = [1 2 3;
4 5 6;
6 7 8]
v = [1;
2;
3]
所需的结果是:
[2 3 4;
6 7 8;
9 10 11]
非常感谢.
推荐答案
An alternative to bsxfun
is to use repmat
and repeat the column vector v
as many times as A
has columns:
A = [1 2 3; 4 5 6; 6 7 8];
v = [1; 2; 3]
A = A + repmat(v,1,3);
这篇关于如何在Matlab中将向量添加到矩阵中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文