
how do i create random normally distributed number array within a set range?
조회 수: 5 (최근 30일)
이전 댓글 표시
i want to create an array of 2000 values that are within the range [-5 5] and are normally distributed around 0?
댓글 수: 0
채택된 답변
Image Analyst
2017년 2월 17일
편집: Image Analyst
2017년 2월 17일
Try
sigma = 5;
data = signma * randn(1,2000);
histogram(data)

Since it's normally distributed, some may lie outside your desired range. So adjust the sigma to adjust the proportion of data that you want to be inside the [-5,5] range.
추가 답변 (1개)
Walter Roberson
2017년 2월 17일
pd = makedist('Normal');
t = truncate(pd, -5, 5);
r = random(t,2000,1);
Warning: the probabilities of a truncated normal distribution do not add up to 1.0 !!
댓글 수: 2
James Tursa
2017년 2월 18일
편집: James Tursa
2017년 2월 18일
doc on truncate indicates that the pdf of the output is re-normalized based on the original probability assigned to the interval, so that the probabilities of the result would in fact add up to 1.0, and the example given for the truncated normal seems to verify this. I.e., the probabilities assigned to the interval in question are scaled up slightly using the amount clipped off of the tails so that the result is a pdf.
참고 항목
카테고리
Help Center 및 File Exchange에서 Descriptive Statistics and Visualization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!