フィルターのクリア

How to generate 0 and 1 with equal probability using 'randi' function?

11 ビュー (過去 30 日間)
Md. Tariqul Amin
Md. Tariqul Amin 2012 年 5 月 27 日
コメント済み: Usman Ali 2014 年 2 月 17 日
Binary random number generator, generating 0 and 1 with equal probability (using 'randi' function). i tried with randi (M, N, [0 1]) to generate random numbers of matrix size MxN in the range 0 and 1 with equal probability.
  1 件のコメント
Md. Tariqul Amin
Md. Tariqul Amin 2012 年 5 月 27 日
i tried with *randi (M, N, [0 1])* to generate random numbers of matrix size MxN in the range 0 and 1 with equal probability. But,it's not working

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

採用された回答

Geoff
Geoff 2012 年 5 月 27 日
You did it backwards. Do this:
nums = randi([0 1], M, N)
Please note that while there is equal probability of randomly generating a zero or a one, that does NOT mean that your matrix will have the same number of zeros and ones.
If you require exactly 50% 0/1, then you need to do this:
nums = mod( reshape(randperm(M*N), M, N), 2 );
Bearing in mind that M*N must be an even number.
  2 件のコメント
Md. Tariqul Amin
Md. Tariqul Amin 2012 年 5 月 28 日
Thanks. I just did that backwards,it's working now
Usman  Ali
Usman Ali 2014 年 2 月 17 日
Hi dear, I have the same question with different parameters. I have 4 different discrete signals. each with 1000 samples per second. I want to generate the sum of all these 4 signals with equal probab such that at the end I get 100 signals (this contains 25% of each signal, 25 copies of same signal at different places). Hope that you get my point. I can apply switch and case for the for signals, only I need to generate number between 1 and 4 with equal probability of occurance

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by