weighted average w/ matlab

222 views (last 30 days)
Regi streer
Regi streer on 2 Sep 2015
Edited: Regi streer on 3 Sep 2015
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?

Accepted Answer

Udit Gupta
Udit Gupta on 2 Sep 2015
You can do something like -
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.
Regi streer
Regi streer on 3 Sep 2015
Edited: Regi streer on 3 Sep 2015
ah okay, it's a normal distribution i missed that. Thanks!

Sign in to comment.

More Answers (1)

dpb on 2 Sep 2015
Have to decide how much you want the weights to be, but the general idea would be sotoo--
>> y=randi([100 150],40,1); % some random data
>> mean(y) % mean should be near 125
ans =
>> w=(y/100).^2;w=w/mean(w); % compute a weight dependent on y; normalize to 1 overall...
>> [min(w) max(w)] % what's look like???
ans =
0.6400 1.4399
>> mean(y.*w) % how much did we change it???
ans =
dpb on 2 Sep 2015
Edited: dpb on 3 Sep 2015
My bad; somehow I read too quickly that the max weight was to be 150, not midpoint. Use a functional with a max at 125; could be the normal pdf as another poster showed or whatever you wish but the same idea works.

Sign in to comment.


Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by