## n d r v

### Senaid Bajric (view profile)

on 17 May 2018 at 11:00
Latest activity Commented on by John D'Errico

### John D'Errico (view profile)

on 18 May 2018 at 14:03
This question was flagged by 2 contributors

Closed

John D'Errico

### John D'Errico (view profile)

on 18 May 2018 at 14:03

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 bother to post questions. Personally, this would make it far less likely for me to bother to answer more of your questions.

### John D'Errico (view profile)

on 17 May 2018 at 11:23

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

### John D'Errico (view profile)

on 17 May 2018 at 16:50

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.

### Senaid Bajric (view profile)

on 17 May 2018 at 17:11
Edited by Senaid Bajric

### Senaid Bajric (view profile)

on 17 May 2018 at 17:13

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