フィルターのクリア

generate a random number according to a probability distribution

3 ビュー (過去 30 日間)
MichMichel
MichMichel 2013 年 2 月 28 日
Hello everyone! :)
I am trying to generate a random number according to a probability distribution that I create. Let me explain:
I have a matrix p (2 * n): p : row 1: 1 2 3 4 5   row 2: 0.1 0.1 0.6 0.2 0
I want to get a number randomly according to the distribution p (2, :) to be able to 1,2,3,4 or 5.
Do you know of a function that can do this in matlab?
Thank you very much
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 2 月 28 日
if p(2,5) is 0, then how would 5 be generated?

サインインしてコメントする。

回答 (2 件)

Tom Lane
Tom Lane 2013 年 2 月 28 日
Check out the datasample function, including its 'Weights' argument.

Image Analyst
Image Analyst 2013 年 2 月 28 日
You can probably find the code for it in this File Exchange submission:

Community Treasure Hunt

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

Start Hunting!

Translated by