Why is the mean function not working?

6 ビュー (過去 30 日間)
Porgs
Porgs 2018 年 5 月 5 日
回答済み: Walter Roberson 2018 年 5 月 5 日
clc
x=randn(1,100000);
y=randn(1,100000);
Za=x+10;
[f,x]=hist(Za,100); %Simulated PDF
bar(x,f/trapz(x,f));
hold on;
title('normalized histogram');
ym = mean(Za)
yv = var(Za)
  2 件のコメント
per isakson
per isakson 2018 年 5 月 5 日
編集済み: per isakson 2018 年 5 月 5 日
What do you mean by "function not working"?
Here, R2016a, your code works according to my expectations.
dpb
dpb 2018 年 5 月 5 日
Sometime you've probably inadvertentedly written mean on the LHS and aliased the function...see what
which mean
returns and try
clear mean
and see if symptoms don't disappear. (The new Crystal Ball Toolbox)

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

採用された回答

Walter Roberson
Walter Roberson 2018 年 5 月 5 日
I am not sure why you say that mean() is not working.
Perhaps you are figuring that the mean of the normal distribution is 0, and that when you add 10 to that, you should get a mean of exactly 10 of the result.
If so then the difficulty with that is that randn() is not the theoretical continuous normal random generator: it is the discrete normal random generator, which emits particular samples that are statistically uniform random in distribution.
The situation is exactly like flipping a single coin and expecting that the result will be a half head and a half tail because that is the long term statistical mean result. Any one coin flip must give a particular result, and although the long term statistical results will tend to 1/2 heads and 1/2 tails, the short term results will likely not be exactly balanced. It is "the Gambler's Fallacy" -- the statistics have no "memory" and probably will not exactly balance over any finite length of time.
If you want to work with theoretical continuous generators to know the theoretical statistical means instead of the discrete means over a given set of samples, then you need to use the continuous generation functions in the Statistics Toolbox.

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by