Setting min/max limits to the function random (not rand nor randn)?

3 vues (au cours des 30 derniers jours)
Karim Shalash
Karim Shalash le 18 Jan 2016
Commenté : jgg le 18 Jan 2016
I am using the function RANDOM to generate random numbers with a specific Kernel PDF that I created using FITDIST. Is there a way to control the min/max of the generated random numbers?
pd1 = fitdist((data(:,1)),'Kernel');
Y1 = random(pd1,100000,1);

Réponse acceptée

jgg
jgg le 18 Jan 2016
The easiest way to do this in your context is to restrict the actual PDF you're using to generate the random variable, rather than do a resampling of the random number. You can do this by calling the Support property:
pd = fitdist(x,'Kernel','Support',[100,250])
Where the bound of the support are in this example [100,250]. The random function will then not generate numbers outside this range.
  3 commentaires
jgg
jgg le 18 Jan 2016
Are you sure you executed this properly? You can read the documentation on the "support" property here. Scroll down and look for "support" under the name-value pair arguments section.
For instance, this code works as expected on my PC:
clear
load hospital
x = hospital.Weight;
pd = fitdist(x,'Kernel','Support',[100,250])
Y1 = random(pd,10000,1);
jgg
jgg le 18 Jan 2016
Ah, the issue with your code is that you should call it like:
pd1 = fitdist((stat(:,1)),'Kernel','Support',[3,4])
The support needs to be sorted: [lb,ub]

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by