How to create a random Bernoulli matrix ?
120 次查看(过去 30 天)
显示 更早的评论
I want to create a 256x256 random Bernoulli matrix, how to do that in matlab ?
1 个评论
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
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
2015-10-7
Careful, probability 1/2 might not be! See http://uk.mathworks.com/matlabcentral/answers/246999-probability-1-2-with-matlab-random-number-generators
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 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!