MATLAB: Calculate weighted average of a 2D matrix

weighted average

Dear all, I hope all is well. I am working with a 2D Matrix that is 376×481. I would like to calculate the weighted average of this matrix for each row, such that the desired output should be sized 376 X 1. I would greatly appreciate any help with this problem.
Thanks.

Best Answer

E.g.,
w = 1x481 vector of weights
M = your 376x481 matrix of values
result = sum(M.*w,2) / sum(w);
or
sum(bsxfun(@times,M,w),2) / sum(w);
Related Question