Combination of multiple rows
1 view (last 30 days)
Show older comments
Hi,
I'm trying to make combinations of six of a matrix with two columns and six rows. For example: [2 4; 6 8; 10 12;1 3; 5 7; 9 11]. Two numbers in a same row don't make a combination. For example: a combination with 9 and 11 isn't a good combination. I've tried using 'nchoosek' and then deleting the combinations that have numbers in the same row, but I get an answer that has some combinations that aren't allowed.
code
%
t = [x(:,1);x(:,2)];
C = nchoosek(t,6);
lengte = size(C,1);
for i = 1:lengte
for j = 1:6
if max(C(i,:)==x(j,1)) || max(C(i,:)==x(j,2))
C(i,:) = [];
lengte = size(C,1);
end
end
end
I've also tried deleting using the following code, but it didn't helped:
code
%
for i = 1:6
C = C(any(C==(x(i,1)),2),:) & C(any(C==(x(i,2)),2),:);
end
end
I would really appreciate if any suggestions might be given.
With kind regards
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!