MATLAB: Weighted average w/ matlab

averagmeanrmsstdweightweighted

Hi guys, I have calculated different errors over a range.
let's say a range with a linear space from 100 to 150.
For this range I calculate a variable Y so Y(range).
Now I want to calculate the mean of the variable, but I want to give the values close to 125 more weight than the values close to 100 and 150, with the heaviest weight being 125.
I can't seem to figure it out, can someone help me out?

Best Answer

You can do something like -
weight=normpdf(range,centerPoint,spread);
wAvg = sum(Y(range).*weight)/sum(weight);
In you example centerPoint will be 125, and larger the spread more slowly the weight will decrease away from centerPoint.