フィルターのクリア

How to create a random Bernoulli matrix ?

60 ビュー (過去 30 日間)
Mohab Mostafa
Mohab Mostafa 2015 年 10 月 6 日
コメント済み: Weijian Liu 2022 年 6 月 4 日
I want to create a 256x256 random Bernoulli matrix, how to do that in matlab ?
  1 件のコメント
Bilal Siddiqui
Bilal Siddiqui 2018 年 10 月 2 日
It's simple. A Bernoulli trial produces one of only two outcomes (say 0 or 1). You can use binord. For example p=0.2; n=256; A=binornd(1,p*ones(n));
produces an nxn array of Bernoulli trials which are either 0 or 1 in each outcome. Hope this answers your question.

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

採用された回答

Robert Dylans
Robert Dylans 2015 年 10 月 7 日
編集済み: Robert Dylans 2015 年 10 月 7 日
p=0.5; %probability of success
n=256;
A=rand(n);
A=(A<p)
or
p=0.5;
A=(rand(256)<p)
  5 件のコメント
Walter Roberson
Walter Roberson 2015 年 10 月 7 日
Walter Roberson
Walter Roberson 2015 年 10 月 7 日
If you have a matrix A of 0 and 1 then you can make it a matrix of -1 and +1 by using
A*2 - 1

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

その他の回答 (2 件)

Byron McMullen
Byron McMullen 2021 年 2 月 15 日
I use this.
bernoulli_matrix = randsrc(rows,cols,[-1,1]);
  1 件のコメント
Weijian Liu
Weijian Liu 2022 年 6 月 4 日
In my opinion, this is the best one.

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


Bilal Siddiqui
Bilal Siddiqui 2018 年 10 月 2 日
It's simple. A Bernoulli trial produces one of only two outcomes (say 0 or 1). You can use binord. For example p=0.2; n=256; A=binornd(1,p*ones(n));
produces an 256x256 array of Bernoulli trials which are either 0 or 1 in each outcome. Hope this answers your question.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by