How to create a m*n matrix with 0,1 entries?
1 次查看(过去 30 天)
显示 更早的评论
In this matrix All entries are zeros except for a single 1 in each row and at most a single 1 in each column?
2 个评论
John D'Errico
2017-2-14
Trivial.
eye(m,n)
That fits your requirements.
Do you have some more information on what you really need?
采纳的回答
John D'Errico
2017-2-14
编辑:John D'Errico
2017-2-14
Did you say random until we had to prod you? :)
The requirements imply that m<=n.
A = eye(m,n);
A(randperm(m),randperm(n))
That yields a fixed number of ones. If you want the result to sometimes have less than m ones, then just start with a diagonal matrix with some of the diagonal elements as zero. Then you can define the number of non-zeros in advance. You can even choose the number of them randomly.
help diag
更多回答(1 个)
另请参阅
类别
在 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!