假设 v
是一个行向量(1 x n
矩阵),M
是一个 n x m
的矩阵。
我用以下代码创建“加权向量”(希望注释可以解释它的作用):
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 循环就可以实现这个目标的方法?