Generating a random binary matrix

24 ビュー (過去 30 日間)
imed NASRI
imed NASRI 2014 年 1 月 6 日
コメント済み: Jack Nelson 2020 年 5 月 13 日
Hello,
I want to generate randomly a (nxm) matrix of binary variables (0 and 1) in matlab. Is there someone who has a suggestion? Thanks.

採用された回答

Amit
Amit 2014 年 1 月 6 日
A = randi([0 1], n,m)
  2 件のコメント
imed NASRI
imed NASRI 2014 年 1 月 6 日
Thanks
Jack Nelson
Jack Nelson 2020 年 5 月 13 日
Thanks!

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

その他の回答 (1 件)

Jos (10584)
Jos (10584) 2014 年 1 月 6 日
Some other suggestions
n = 4 ; m = 5 ;
A1 = rand(n,m) < 0.5 % a logical array consuming little memory
A2 = round(rand(n,m))
N0 = ceil(n*m/3) ; % specify some exact number of zeros
A3 = ones(n,m) ; A3(1:N0) = 0 ; A3(randperm(numel(A3))) = A3
  1 件のコメント
imed NASRI
imed NASRI 2014 年 1 月 6 日
Thanks :)

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by