フィルターのクリア

How to generate a binary matrix with a fixed sum in rows and a changeable sum in columns?

4 ビュー (過去 30 日間)
Ideth Kara
Ideth Kara 2022 年 8 月 21 日
コメント済み: Torsten 2022 年 8 月 22 日
Hello everyone !
i have a binary matrix (M,N) .I want to get sum equal to 1 in each row and in columns sum varies between [1 and 6], the sum of all matrix equal to M.
i will be grateful if you could help me
  3 件のコメント
Ideth Kara
Ideth Kara 2022 年 8 月 21 日
how can i put "1" with different index in columns in order to get sum = 3 in each columns and "1" in each row
Torsten
Torsten 2022 年 8 月 22 日
What about
[1 0
1 0
0 1
0 1
0 1
0 1]
?
Do you see how to construct one such matrix ?
Of course, you can permute the rows arbitrarily - the resulting matrix will still fulfill the requirements.

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

回答 (1 件)

Bruno Luong
Bruno Luong 2022 年 8 月 21 日
編集済み: Bruno Luong 2022 年 8 月 21 日
A=kron(eye(5),ones(3,1));
A=A(randperm(end),randperm(end))
A = 15×5
0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0
sum(A,1)
ans = 1×5
3 3 3 3 3
sum(A,2)
ans = 15×1
1 1 1 1 1 1 1 1 1 1
  4 件のコメント
Ideth Kara
Ideth Kara 2022 年 8 月 22 日
can you explain it more in the example that you mentioned above?
Bruno Luong
Bruno Luong 2022 年 8 月 22 日
編集済み: Bruno Luong 2022 年 8 月 22 日
The first line create the specific matrix that meet the row/column sum requirements.
The second line permutes rows and columns randomly, create a new random matrix, the sums are invariants under these operations, so the new matrix still meets the sum requirements.

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

カテゴリ

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