필터 지우기
필터 지우기

r = randi(10,100,1) but using non-uniform distribution

조회 수: 8 (최근 30일)
Nuchto
Nuchto 2013년 4월 12일
답변: Steven Lord 2020년 11월 4일
How to create random number from a range non-uniformly distributed?
Thanks!
  댓글 수: 3
Vikas Tiwari
Vikas Tiwari 2020년 11월 4일
how to get random normally distributed numbers in 5by7matrix?

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

채택된 답변

the cyclist
the cyclist 2013년 4월 12일
편집: the cyclist 2013년 4월 12일
As Jan comments, there are literally an infinite number of possible distributions. (In particular, do you want integers or real numbers in that range?)
If you have the Statistics Toolbox, there are several random number generators available. You can type
>> doc random
to see a list of possibilities. Another command that might be handy is randsample(). You can specify a particular frequency distribution for the random numbers. See
>> doc randsample
for details.

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 11월 4일
One way to generate numbers from a "weighted die" is to use discretize with a vector of probabilities. In this example, the weight vector P indicates that I want to generate numbers between 1 and 4 but 1 is twice as likely as each of the other three numbers.
P = [2 1 1 1];
Scale the weight so they sum to 1.
prob = normalize(P, 'scale', sum(P));
Make a vector of probability edges
cprob = cumsum([0 prob]);
Generate some sample data and discretize that sample data to determine into which bin (defined by the probability edges) each of the sample data point falls.
x = rand(1, 1e5);
roll = discretize(x, cprob);
Show a histogram of the rolls and you should see the bar for 1 is twice as high as the bars for 2, 3, and 4.
histogram(roll, 'Normalization', 'probability')

Community Treasure Hunt

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

Start Hunting!

Translated by