How to generate a random number from a user defined discrete uniform distribution in Matlab ?

6 vues (au cours des 30 derniers jours)
Hi there,
Imagine that I have written the following code in MATLAB.
numItems = 100 ;
Levels = [0.25, 0.5, 0.75, 1.0]
prob = [.25, .25, .25, .25]
% prob can be any set of probability values.
I want to generate a discrete uniform distribution with values Levels for a vector of numItems elements considering the values of prob.
If I simply explain, I need to get something similar to np.random.choice in Numpy.
I tried with unirnd but it is only possible with positive integeres by not floating point numbers.
Can anyone please help me with this ?
Thanks.

Réponse acceptée

Walter Roberson
Walter Roberson le 17 Mai 2020
randsample() and provide a weights vector.

Plus de réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by