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

3 views (last 30 days)
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);

Accepted Answer

jgg
jgg on 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 Comments
jgg
jgg on 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 on 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]

Sign in to comment.

More Answers (0)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!