Generate random binary matrix (Matlab)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Afluo Raoual
am 2 Jun. 2021
Bearbeitet: Afluo Raoual
am 18 Jun. 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.
0 Kommentare
Akzeptierte Antwort
David Hill
am 2 Jun. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!