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

3 ビュー (過去 30 日間)
Karim Shalash
Karim Shalash 2016 年 1 月 18 日
コメント済み: jgg 2016 年 1 月 18 日
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