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

2 views (last 30 days)
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.

Answers (0)

Community Treasure Hunt

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

Start Hunting!