Let v
be a row vector (1 x n
matrix) and M
be a n x m
matrix.
I use the following piece of code to create a "weighted vector" (I hope the comments explain what it's supposed to be doing):
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
Now the actual question: I have to do the same calculation for a lot of input vectors v
. So instead I would like to input a matrix V
that contains the vectors v
as rows and output a matrix that contains the weighted vectors as rows. Is there any way to do this without using for loops?