Random Number Sampling Between a Specific Range of a Non-Uniform Distribution

1 回表示 (過去 30 日間)
Sunkensie
Sunkensie 2015 年 7 月 29 日
コメント済み: Torsten 2015 年 7 月 29 日
I need to sample from a Gaussian mixture distribution (GMmodel) using Monte Carlo method. For certain scenarios values need to be sampled from a specific range as determined by the x-axis (B). Currently I'm attempting to use logical indexing to do so, however I'm either missing something or have made an error as so far the values I get at the end don't make sense - most values are negative, which is impossible given the system I'm attempting to model.
Here is the relevant code:
load('T.mat');
load('B.mat');
t = 'baseline SPRING'
for i = 1:Mcrun;
r = GMmodel.random(1);
if t == 'baseline SPRING'
LOGIC=r(:,1)<=10.57&r(:,1)>0;
elseif t == 'baseline SUMMER'
LOGIC=r(:,1)<=35&r(:,1)>0;
Bm=r(:,1).*LOGIC;
Tm=r(:,2).*LOGIC;
From here I plug Bm and Tm into equations. I've traced back the error (negative values) here.
Would using logical indexing the best way to do this type of sampling? Is there a better method?
I'm new to MatLab and would greatly appreciate any guidance.
  1 件のコメント
Torsten
Torsten 2015 年 7 月 29 日
You forgot the "end"-statement after the line "LOGIC=r(:,1)<=35&r(:,1)>0;".
Best wishes
Torsten.

サインインしてコメントする。

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by