matrix of zeros and ones within number of zeros in each rows in-between a limit
조회 수: 2 (최근 30일)
이전 댓글 표시
want to have a 30x40 matrix of zeros and ones; however in each row total number of 'ones' must be within 10 to 20.
댓글 수: 0
채택된 답변
추가 답변 (1개)
John D'Errico
2015년 10월 9일
So generate a matrix with random ones and zeros. Discard any rows that fail this test, and regenerate just those rows. WTP?
Since you have not said what the distribution of the number of ones is, I cannot offer a complete solution, but it is simple in any case. If you will have 17 ones in a row, then generate a row vector with 17 ones, and 23 zeros. Then randomly permute the elements.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!