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

7 次查看(过去 30 天)
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);

采纳的回答

jgg
jgg 2016-1-18
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 个评论
jgg
jgg 2016-1-18
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 2016-1-18
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]

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by