Generate random binary matrix (Matlab)

1 回表示 (過去 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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by