how chose a number with unequal probability?

1 次查看(过去 30 天)
My question is if I use randi function and say between 1 : 100, it chooses randomly a number giving equal probability to all numbers in between. Suppose I want to chose a number between 1 and 100 but give different probability for each number say proportional to the number itself.. so that 1 has a much lower probability to pick compared to 100 for e.g. how would I do that with randi function? Is that possible at all? Thanks in advance for any help.

采纳的回答

Steven Lord
Steven Lord 2017-1-23
Use the randsample function from Statistics and Machine Learning Toolbox with a vector of weights.

更多回答(1 个)

Matt J
Matt J 2017-1-23
编辑:Matt J 2017-1-23
delta=1/(100*101/2);
probs=[0,cumsum((1:100)*delta)];
[~,~,theresult]=histcounts(rand,probs);

类别

Help CenterFile Exchange 中查找有关 Get Started with Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by