【发布时间】:2015-12-06 19:18:36
【问题描述】:
设v 为行向量(1 x n 矩阵),M 为n x m 矩阵。
我使用以下代码创建一个“加权向量”(我希望 cmets 解释它应该做什么):
weighted_M = bsxfun(@times,v',M);
%creates a matrix with the i-th row of M being weighted (multiplied) by the i-th element of v
weighted_v = sum(weighted_M);
%sums the columns of weighted_M
现在的实际问题是:我必须对大量输入向量 v 进行相同的计算。因此,我想输入一个矩阵V,其中包含向量v 作为行,并输出一个矩阵,其中包含加权向量作为行。有什么方法可以在不使用 for 循环的情况下做到这一点?
【问题讨论】:
标签: matlab matrix vectorization bsxfun