How to create random binary matrix with specified number of ones in each row and column?

4 ビュー (過去 30 日間)
Number of raws = M, number of columns = N, number of one's in each row = Nrow, number of one's in each column = Ncolumn.

採用された回答

Walter Roberson
Walter Roberson 2019 年 1 月 13 日

その他の回答 (1 件)

Jan
Jan 2017 年 4 月 25 日
編集済み: Jan 2017 年 4 月 25 日
This will not work in general: You cannot e.g. place 2 elements per row and per column in a 5 x 5 matrix:
1 0 0 0 0 % <-- here one 1 is missing and cannot be inserted
1 1 0 0 0
0 1 1 0 0
0 0 1 1 0
0 0 0 1 1
But you can create a 6x6 matrix with 3 ones in each column and row.
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 1 月 13 日
Your example does not appear to be complete.
[0 0 1 1 0; 0 1 1 0 0; 1 1 0 0 0; 1 0 0 0 1; 0 0 0 1 1]
ans =
0 0 1 1 0
0 1 1 0 0
1 1 0 0 0
1 0 0 0 1
0 0 0 1 1
This is a 5 x 5 matrix with two 1's per row and per column.
Furthermore for your original matrix, insert the 1 at the top right corner:
1 0 0 0 1
1 1 0 0 0
0 1 1 0 0
0 0 1 1 0
0 0 0 1 1

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by