本文介绍了如何在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]非常感谢.
推荐答案bsxfun的替代方法是使用 repmat ,并重复列向量v与A具有列的次数相同:
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中将向量添加到矩阵中?
发布评论