Generating random variables from normal distribution
이전 댓글 표시
I generated random variables from a normal distribution. I used this: normrnd(mu, sigma, N, 1). Mu = 0.146053128 and sigma = 0.13470517. The problem is some of the random numbers generated are negative.
My question is: 1. How do I generate all positive (non-negative) random numbers from normal distribution? 2. Can someone kindly explain why the negative numbers were generated since I have no idea and cannot explain why that happened.
Please I really need help.
Thanks in advance
Ruby
채택된 답변
추가 답변 (2개)
Matthew
2012년 9월 25일
If you just want to truncate the tail so that you don't get negative numbers, the below would work.
normArray = normrnd(mu, sigma, N, 1);
normArray(normArray<0) = 0;
댓글 수: 3
Matt Fig
2012년 9월 25일
Except then normArray is not a normal distribution...
N = normrnd(.1, .9, 1000000, 1);
subplot(1,2,1)
hist(N,-6:.05:6) % What a normal dist looks like
N(N<0) = 0;
subplot(1,2,2)
hist(N,-6:.05:6) % Not a normal dist.
mohammed sportman
2012년 10월 7일
how r u math can you help me to chose random number from matrix with possible to repeat the number more than once time (possion distribution)
Image Analyst
2012년 10월 8일
Matthew's is not normal, but Matt's isn't exactly what was asked for either. It's still normal but the mean shifted upwards from the desired location. For another way to do it (again, not producing what was wanted, or normal), you can simply remove the negative numbers altogether:
normArray(normArray < 0) = []; % Eliminate negative numbers.
This will also reduce the number of elements in the array of course, so you might want to ask for way more than is necessary and then truncate to the number you want:
normArray(desiredNumberOfElements+1:end) = []; % Get rid of extra unneeded #'s.
or alternatively:
normArray = normArray(1:desiredNumberOfElements); % Get rid of extra unneeded #'s.
카테고리
도움말 센터 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!