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

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by