Change index of element in matrix with constraint

Hi all!
i have i binary matrix A(180,60), in each column i have 3 "ones" and only "one" by row,the sum of each row equal to 1.
i used this , but i had 3 "ones" in the 3 successive rows. How can i change the index of "1"?
M = 180; N =60;
k = 3;
C = repelem(eye(N), k, 1);
NEED URGENT HELP !

Réponses (1)

A = repmat(eye(6), 3, 1) % change 6 to 60
A = 18×6
1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0
% if you need random permutation
B = A(randperm(6*3), :)
B = 18×6
0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0

7 commentaires

i have a constraint :
after 3 "ones" in the 3 successive rows , i can't put "1" in the first column.
after 3"ones" in the next successive rows, i can't put "1" in the second column,...
Chunru
Chunru le 22 Août 2022
Then "A" in above code always satisfies your requirement (since no 3 "ones" in the 3 successive rows). Or do you also have other requirements?
In A , there is "1" in the 7th row.
i need 3 'ones' in the 3 successive rows but with different position. as condition , after the 3 rows , the rest os first column will be "zero", after the next 3 rows , the rest of second column "zero",...
like this :
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 1 0 0 0
0 1 0 0 0 0
0 0 0 1 0 0
0 0 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
Chunru
Chunru le 22 Août 2022
Modifié(e) : Chunru le 22 Août 2022
Then how can you ensure sum of each column is 3?
the maximum is 3 , it means that i can have 2 "ones" per column or one per column.
Chunru
Chunru le 22 Août 2022
I could not understand your requirements:
"i need 3 'ones' in the 3 successive rows but with different position. as condition , after the 3 rows , the rest os first column will be "zero", after the next 3 rows , the rest of second column "zero",..."
i will try to explain by using independent matrix :
A [3,6]
1 0 0 0 0 0
1 0 0 0 0 0
0 1 0 0 0 0
B[3,7]
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
C[3,8]
0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
D[3,9]
0 0 0 1 0 0 0 0 0
0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0
until i get [3,60]. but all this will be in the same matrix [180,60]

Connectez-vous pour commenter.

Catégories

Question posée :

le 22 Août 2022

Commenté :

le 22 Août 2022

Community Treasure Hunt

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

Start Hunting!

Translated by