フィルターのクリア

function that can do random drawing

3 ビュー (過去 30 日間)
jenka
jenka 2012 年 1 月 30 日
I have the following probabilities: 0.8 for category 1 and 0.2 for category 0. I need to randomly draw a category (0/1) such that the it satisfies the probability distribution. Is there such a thing in matlab? Thanks

回答 (1 件)

Wayne King
Wayne King 2012 年 1 月 30 日
You can just use rand.
for nn = 1:1000
drawnum = rand(1);
if( drawnum <= 0.2)
category(nn) = 1;
else
category(nn) = 0;
end
end

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by