Combination of multiple rows

1 vue (au cours des 30 derniers jours)
Paulo
Paulo le 21 Oct 2015
Commenté : TastyPastry le 21 Oct 2015
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
  1 commentaire
TastyPastry
TastyPastry le 21 Oct 2015
What's the output you're looking for?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by