让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
Run Code Online (Sandbox Code Playgroud)
现在问题是:我必须对很多输入向量进行相同的计算v.因此,我想输入一个V包含矢量v作为行的矩阵,并输出一个包含加权矢量作为行的矩阵.有没有办法在不使用for循环的情况下执行此操作?