필터 지우기
필터 지우기

Generating a random binary matrix

조회 수: 87 (최근 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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by