MATLAB: How to calculate a weighted mean in Matlab

mean2weighted averageweighted mean

I have a 180-by-360 matrix of (surface temperature) values and I want to calculate a weighted average of all values given in this matrix. However, I need to weight these values with respect to latitude. Is there a way to calculate a weighted mean in Matlab? Please help me.
Thanks in advance for any help!
– Jan-Erik

Best Answer

If A is your 180x360 matrix and W is a 180x1 vector of weights for the latitudes, do
weighted_mean = mean(W.'*A,2);