Why is the mean function not working?
6 views (last 30 days)
Show older comments
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 Comments
per isakson
on 5 May 2018
Edited: per isakson
on 5 May 2018
What do you mean by "function not working"?
Here, R2016a, your code works according to my expectations.
dpb
on 5 May 2018
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)
Accepted Answer
Walter Roberson
on 5 May 2018
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 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!