Divide group into subgroups
显示 更早的评论
I have a matrix 5x5 and i managed from this matrix to create a matrix 5x10 by creating a subgroup of 2 in each column.
So Matrix =
0 0 0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 1
I want to tell that row 1 belongs to group 2, row 2 belongs to group 1, row 3 belongs to group 2, row 4 belongs to group 3 and row 5 belongs to group 5!
Thank you so much
采纳的回答
更多回答(1 个)
Walter Roberson
2016-4-7
group = sum( Matrix(1:2:end) | Matrix(2:2:end) .* repmat( 1:size(Matrix,2)/2, size(Matrix,1), 1), 2);
Note: this may give unexpected answers if you have multiple 1's in the same row.
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!