フィルターのクリア

randsample([0 1],1,true,[1 - p p]) ..... with p as a vector?

2 ビュー (過去 30 日間)
Ulrik William Nash
Ulrik William Nash 2018 年 11 月 29 日
回答済み: Bruno Luong 2018 年 11 月 29 日
I have the following code that generates a 0 or a 1 depending on the probability p:
randsample([0 1],1,true,[1 - p p])
But suppose my probability was taken from a vector of other probabilities. Is it possible to ammend my code to handle all probabilities at once, rather than looping through the vector for each probability?
  2 件のコメント
Rik
Rik 2018 年 11 月 29 日
I don't understand your question, nor do I have the toolbox for this function, so I can't play around with it for you.
Ulrik William Nash
Ulrik William Nash 2018 年 11 月 29 日
p in the code is a single value. I am asking if this function can handle multiple values of p at once, thus generating a vector of 0's and 1's corresponding to a vector of p values.

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

回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 11 月 29 日
編集済み: Walter Roberson 2018 年 11 月 29 日
double( rand(size(p)) < p )

Bruno Luong
Bruno Luong 2018 年 11 月 29 日
Assuming yoy have p in a vector
r = rand(size(p))<p

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by