Generate random binary matrix (Matlab)
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!