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?

 採用された回答

Udit Gupta
Udit Gupta 2015 年 9 月 2 日

1 投票

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.

3 件のコメント

Regi streer
Regi streer 2015 年 9 月 2 日
the spread function does not work (Undefined function or variable 'spread'.)
Udit Gupta
Udit Gupta 2015 年 9 月 2 日
spread is not a function. It can be any value. Bigger the value bigger the spread is. For example spread = 100 will provide a wide and gentle slope and spread = 50 will produce a steeper slope.
Regi streer
Regi streer 2015 年 9 月 3 日
編集済み: Regi streer 2015 年 9 月 3 日
ah okay, it's a normal distribution i missed that. Thanks!

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2015 年 9 月 2 日

0 投票

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 =
123.9750
>> 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 =
128.0471
>>

2 件のコメント

Regi streer
Regi streer 2015 年 9 月 2 日
But this does not give me exactly more weight at 125 in my problem right?
dpb
dpb 2015 年 9 月 2 日
編集済み: dpb 2015 年 9 月 3 日
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2015 年 9 月 2 日

編集済み:

2015 年 9 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by