20 value from a normal distribution..
2 views (last 30 days)
I have mu and sigma (stand deviation) i.e. mean=20 and sigma=4. I am generating data with normal distribution from these parameters.
I need to select 20 values ranges between 8 to 32 from this distribution..How to do so?
Thanks in advance
Mu = 20;
sigma = 4;
N = normrnd(Mu, sigma, 100000, 1);
Michael Haderlein on 7 May 2015
Edited: Michael Haderlein on 7 May 2015
First, make sure that there are enough numbers available (with the values you use, this might not be a problem):
while sum(N>=lo & N<=hi)<num
N(N<lo | N>hi)=round(normrnd(Mu,sigma,sum(N<lo | N>hi),1));
Then, take the first 20 values which are in the respective interval:
ind=find(N>=lo & N<hi,num,'first');