# 20 value from a normal distribution..

조회 수: 4(최근 30일)
joy 2015년 5월 7일
댓글: joy 2015년 5월 7일
Hi,
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?
Mu = 20;
sigma = 4;
N = normrnd(Mu, sigma, 100000, 1);
N=round(N);
hist(N,0:1:60);

댓글을 달려면 로그인하십시오.

### 채택된 답변

편집: Michael Haderlein 2015년 5월 7일
First, make sure that there are enough numbers available (with the values you use, this might not be a problem):
lo=8;hi=32;num=20;
while sum(N>=lo & N<=hi)<num
N(N<lo | N>hi)=round(normrnd(Mu,sigma,sum(N<lo | N>hi),1));
end
Then, take the first 20 values which are in the respective interval:
ind=find(N>=lo & N<hi,num,'first');
N(ind)
##### 댓글 수: 5표시숨기기 이전 댓글 수: 4
joy 2015년 5월 7일
Thank you. I shall make those corrections.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Random Number Generation in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by