How do I generate numbers from discrete bivariate distribution?
    3 次查看(过去 30 天)
  
       显示 更早的评论
    
I would like to know how I can generate sample numbers from discrete bivariate distribution assuming that I have vectors x and y and a discrete probability matrix P to describe the two variables.
采纳的回答
  MathWorks Support Team
    
 2009-6-27
        If P is an unconditional probability matrix and sum of all entries equal to '1', where P(i, j) describe the probability choice (xi, yj), then the RANDSAMPLE function can be used to choose the pair (x,y) using probability matrix P. For example,
P = [0.083333  0.05           0.033333
         0.1            0.16667     0.066667
         0.1            0.1             0.3];
sum_P = sum(P(:))
x = [1 2 3]';
y = [1 2 3]';
xy = [x repmat(y(1), length(x),1); x repmat(y(2), length(x),1); x repmat(y(3), length(x),1)];
%%generate random row number of (x,y) pair
row = randsample(9,10,true, P(:) );
xy_sample = xy(rows,:);
 sum_P =
     1
 xy_sample =
      2     2
      3     2
      3     1
      3     2
      1     1
      3     2
      3     3
      3     3
      3     3
      3     3
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
