How do I generate a sampled sequence with frequncy p(n)

I have a 1xn vector of observations X(n)and a vector of probabilities p(n). How do I simulate sampling from this distribution where the frequency of picking observation x(n) is proportional to p(n)? Thanks

回答 (1 件)

Jos (10584)
Jos (10584) 2014 年 9 月 22 日

0 投票

See RANDP on the file exchange
X = [10 20 30] % observations
p = [50 30 20] % (relative) probabilities
N = 20 ;
i = randp(p,1,N)
Sample = X(i)

カテゴリ

ヘルプ センター および File ExchangeSimulink Design Optimization についてさらに検索

タグ

質問済み:

2014 年 9 月 22 日

回答済み:

2014 年 9 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by