필터 지우기
필터 지우기

random number generation within the defined range

조회 수: 3 (최근 30일)
Dyno
Dyno 2012년 4월 10일
Hii,
First of all thanks to everybody for giving time to respond to my question, which is as follows:
I am trying to generate a random number between -.4776 and .5004 with the mean as .02528 and standard deviation as .116. I tried using the following command but its violating the specified range.
r = -.4776 +(.5004+.4776).*normrnd(.02528, .116,179290, 1)
Any help in this regard??
Thanks a lot!!

채택된 답변

Daniel Shub
Daniel Shub 2012년 4월 10일
You cannot use a Gaussian/normal distribution and expect all the values to fall into a particular range. When you specify a range the most common distribution is a uniform distribution. For your range a uniform distribution does not have the desired mean or standard deviation.

추가 답변 (2개)

Junaid
Junaid 2012년 4월 10일
As Daniel suggested that we might not get exactly what you want. But there can be several tricks. Once possible trick is that you generate random numbers by defining the range;
m + s to m - s;
where m, and s are required mean and standard deviation.
ex.
m = .02528;
s = .116;
a = m + s;
b = abs(m - s);
% now generating the numbers between a and b.
g = a + (b-a).*rand(100,1);
You get mean and standard deviation very close to you required values.
  댓글 수: 1
Daniel Shub
Daniel Shub 2012년 4월 10일
I think you reversed the m and the s, but either way this does not really give the desired range (although it doesn't violate the range either), and has the incorrect standard deviation. The standard deviation of a uniform distribution is |a-b|/sqrt(12).

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


Dyno
Dyno 2012년 4월 10일
Thank you for your suggestion:
@ Junaid i tried working your trick but it dosent seem to solve my problem. @ Junaid and Daniel: To briefly describe my problem, i am modelling the error pattern present at my sensor outputs. On investigating the error pattern i found the mean and the standard deviation alongwith its range. I thought if i could generate the same distribution using the given statistical properties (i.e., mean, median and the range) i would be able to compensate for the error present at my sensor output. It seems i am not in right track, I would have to look for another analysis to compensate.
I would really appreciate if you have any suggestions.
Thanks!!
  댓글 수: 2
Daniel Shub
Daniel Shub 2012년 4월 10일
You should edit your question to include this information instead of posting it as an answer.
Image Analyst
Image Analyst 2012년 4월 10일
Huh? You want to try to model your fixed pattern noise of your sensor (basically differences in the sensitivity or responsivity of the detectors) by creating a simulated noise pattern rather than using the actual noise pattern that you can measure? Why would you want to do that when you have the actual pattern? It's fairly simple: Just divide by your actual pattern to correct your signal, assuming you've collected enough data to give you a good estimate of the "true" pattern and it's not just some noisy mess.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by