matlabmatrixmatrix-multiplicationvector-multiplication

How get mean of weighted matrixes without loop?


I have groups of scalars and matrixes respertively:

w1, w2...wn
A1, A2... An

How get

w1*A1 + w2*A2 + ... + wn*An

without loop? And how efficiently get

w1*(b1*c1) + w2*(b2*c2) + ... + wn*(bn*cn)

Where bi and ci are vectors but bi*ci is matrix, not a scalar?


Solution

  • edit: I have a better solution.

    If your matrices An are stored in a 3-D matrix of size P x Q x N such that An = A(:,:,n) for n = 1, 2, ..., N and your weights are stored in a weight vector w of size 1 x N then the following command does the weighted average:

    B = reshape(w*reshape(permute(A,[3,1,2]),N,[]),[P,Q]);