Why is the mean function not working?
6 次查看(过去 30 天)
显示 更早的评论
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
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
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
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!