How do I generate numbers from discrete bivariate distribution?

2 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
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
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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by