Effacer les filtres
Effacer les filtres

Generate random binary matrix (Matlab)

4 vues (au cours des 30 derniers jours)
Afluo Raoual
Afluo Raoual le 2 Juin 2021
Modifié(e) : Afluo Raoual le 18 Juin 2021
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.

Réponse acceptée

David Hill
David Hill le 2 Juin 2021
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 commentaire
Afluo Raoual
Afluo Raoual le 7 Juin 2021
@David Hill Yeah unfortunaltely it doesn't work with other cases

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by