I have a matrix in MATALB with elements {0, 1}. I want to collect those 1in groups following these rules:
- I start with anyone
1in the matrix, and I put it, say, in group1. - After I go over and see if there is a corresponding row and column. If so, I add all of this row and column to
group1. - Each time I find one in a row or in a column, I go and I see the corresponding row and column, and I add them to this group (
group1). - If I do not find anyone else in the corresponding row or column, I will move on to the next group, say,
group2 - I continue this way until one is found in the matrix.
Here I will give a simple example:
A = [ 1 0 0 1 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
0 1 1 0 0 ]
group1 = {(1, 1)}
% I put in group1 the first element A(1, 1) (arbitrarly)
% Since in row 1 and column 1 we have A(1, 4) = 1 and A(2, 1) = 1 so I
% add them to group1
group1 = {(1, 1), (1, 4), (2, 1)}
% We see now that I have no one that correspond to the element A(2, 1) since
% A(2, :) = 0 and A(:, 1) = 0. But I have ones that correspond to element A(1, 4)
% which are A(3, 4) and A(4, 4) so I add them to group1
group1 = {(1, 1), (1, 4), (2, 1), (3, 4), (4, 4)}
% Also A(3, 4) and A(4, 4) have no corresponding ones. Hence I stop and I go to group2
group2 = {(5, 2)}
% I do the same and I get:
group1 = {(1, 1), (1, 4), (2, 1), (3, 4), (4, 4)}
group2 = {(5, 2), (5, 3)}
, , :
for i = 1:size(A, 1)
e{i} = find(A(i, :)~=0);
end
for j = 1:size(A, 1)
for i = e{j}
a{i} = find(A(:, i)~=0);
end
end
, ? ?
.