I have a matrix of strings of Nbinary vectors, i.e.
mymatrix = [ 1 0 0 1 0;
1 1 0 0 1;
0 1 1 0 1;
0 1 0 0 1;
0 0 1 0 0;
0 0 1 1 0;
.... ]
where I would like to find combinations of strings that when added together will get me exactly:
[1 1 1 1 1]
Thus, in the example above, the combinations that will work are 1/3, 1/4/5and 2/6.
The code for this now:
i = 1;
for j = 1:5
C = combnk([1:N],j); % Get every possible combination of rows
for c = 1:size(C,1)
if isequal(ones(1,5),sum(mymatrix(C(c,:),:)))
combis{i} = C(c,:);
i = i+1;
end
end
end
But, as you could imagine, this takes some time, especially because of this combnk.
What could be a useful algorithm / function that can help me speed this up?
source
share