Change index of element in matrix with constraint
1 次查看(过去 30 天)
显示 更早的评论
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 !
1 个评论
回答(1 个)
Chunru
2022-8-22
A = repmat(eye(6), 3, 1) % change 6 to 60
% if you need random permutation
B = A(randperm(6*3), :)
7 个评论
Chunru
2022-8-22
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",..."
另请参阅
类别
在 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!