필터 지우기
필터 지우기

Generate random binary matrix (Matlab)

조회 수: 3 (최근 30일)
Afluo Raoual
Afluo Raoual 2021년 6월 2일
편집: Afluo Raoual 2021년 6월 18일
Dear members
I want generate binary matrix of dimensions M*N in which the number of ones in each row (ones_row) and column (ones_column) is equal.

채택된 답변

David Hill
David Hill 2021년 6월 2일
Brute force might work for you. Obviously, some combinations of N,M,n,m will not work.
N=10;M=5;%matrix size
n=6;%number of ones in a row
m=3;%number of ones in a column
a=[ones(1,n),zeros(1,N-n)];
b=a;
c=zeros(M,N);
while ~all(b==m)
for k=1:M
c(k,:)=a(randperm(N));
end
b=sum(c);
end
  댓글 수: 1
Afluo Raoual
Afluo Raoual 2021년 6월 7일
@David Hill Yeah unfortunaltely it doesn't work with other cases

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by