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일

3 개 추천

p=0.5; %probability of success
n=256;
A=rand(n);
A=(A<p)
or
p=0.5;
A=(rand(256)<p)

댓글 수: 5

Mohab Mostafa
Mohab Mostafa 2015년 10월 7일
Thank you so much, another question (if it's fine with you), how to generate a random Gaussian matrix ? (also 256x256)
A=normrnd(mean,standard dev,m,n);
For a cluster around a an average of '0' with sigma 1:
A=normrnd(0,1,256,256);
Mohab Mostafa
Mohab Mostafa 2015년 10월 7일
and what if I want a -+1 Bernoulli matrix to be used in compressed sensing as a sensing matrix ?
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일

3 개 추천

I use this.
bernoulli_matrix = randsrc(rows,cols,[-1,1]);
Bilal Siddiqui
Bilal Siddiqui 2018년 10월 2일

1 개 추천

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.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2015년 10월 6일

댓글:

2022년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by