Asked by Senaid Bajric
on 17 May 2018

If normal random variable have parameters N(0,1), how can I find results from possible 1000 which I expect to show in interval 1-2

Answer by John D'Errico
on 17 May 2018

This is an extremely confusing question. Usually, that implies the person asking it is also confused.

It sounds like you have a population of 1000 samples from a normal random variable. For example,

z = randn(1,1000);

So the vector z will have 1000 samples. Now, do you want to do something with only those samples that lie in the interval [1,2]? If so, then you could just use find, testing if z>=1 and z<=2. Even simpler is just this:

z12 = z(z >= 1 & z <= 2);

If that is not what you are looking to see, then you need to VERY clearly explain your problem.

John D'Errico
on 17 May 2018

Actually, the theoretically expected frequency is

format long g diff(normcdf([1 2])) ans = 0.135905121983278

NOT 0.1365. So I'm not sure what you used to get that estimate.

Anyway, what is the problem? Do you seriously expect to see EXACTLY 136 samples in those bounds? If you do, when why not expect EXACTLY 135.905121983278 samples in that interval? Surely you see the problem in assuming the frequency to be exact.

x = randn(1,1000); sum(x >= 1& x <= 2) ans = 111

Which is reasonably close. Remember, these are samples taken from a normal distribution. The larger the sample size, the closer you will expect the fraction to be close to 13.59...%. That is just basic statistics.

x = randn(1,1000000); sum(x >= 1& x <= 2)/numel(x)*100 ans = 13.607

x = randn(1,10000000); sum(x >= 1& x <= 2)/numel(x)*100 ans = 13.5921

At the other extreme, if I sample from a Normal distribution, 50% of the time, the number "should" be greater than 0. Surely you agree with that? But what if I take only ONE sample? Sometimes it will be positive, sometimes negative. But a limited sample population will never show the EXACT distribution frequency, based on theory. So even though I expect 50% of my samples to exceed 0, oops! Look what happened:

randn(1) ans = -0.633677491587928

100% of my samples from this latest set were less than 0.

Again, this is all just basic statistics, and understanding random variables.

Sign in to comment.

Answer by Senaid Bajric
on 17 May 2018

Edited by Senaid Bajric
on 17 May 2018

I understood it at the end and I did it alone meanwhile. Thank you for trying to help me.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## John D'Errico (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/401195-normal-distribution-random-variable#comment_569366

When you delete the question and even the subject, you insult those who bothered to spend the time to answer your question. You hurt the answers site.

If you cannot leave your question as it is, then you should not post questions.

## Rena Berman (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/401195-normal-distribution-random-variable#comment_573190

(Answers Dev) Restored edit

Sign in to comment.