randsample([0 1],1,true,[1 - p p]) ..... with p as a vector?
1 回表示 (過去 30 日間)
古いコメントを表示
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
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.
回答 (2 件)
Walter Roberson
2018 年 11 月 29 日
編集済み: Walter Roberson
2018 年 11 月 29 日
double( rand(size(p)) < p )
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Biomedical Imaging についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!