Combination of multiple rows

1 回表示 (過去 30 日間)
Paulo
Paulo 2015 年 10 月 21 日
コメント済み: TastyPastry 2015 年 10 月 21 日
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 件のコメント
TastyPastry
TastyPastry 2015 年 10 月 21 日
What's the output you're looking for?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by