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

조회 수: 2 (최근 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