All possible combinations (subgroups vary in size) of elements in a vector

Hey,
I am trying to find a solution for the following problem:
I want to generate every possible combination of elements in a vector. The vector elements should always be split up in 2 groups. The groups can vary in size (number of elements), but all elements have to been included in the groups. The number of elements in a vector varies from 3 to 12.
Vector1 = [1 2 3 4]
Possible subgroups:
1 vs. 2,3,4
2 vs. 1,3,4
3 vs. 1,2,4
4 vs. 1,2,3
1,2, vs. 3,4
1,3 vs. 2,4
1,4 vs. 2,3
Vector2 =[1 2 3 4 5 6]
Size Subgroup1 = 1, Subgroup2 = 5
1 vs. 2,3,4,5,6
2 vs. 1,3,4,5,6
6 vs 1,2,3,4,5
Size Subgroup1 = 2, Subgroup2 = 4
1,2 vs. 3,4,5,6
1,3 vs. 2,4,5
Size Subgroup1 = 3, Subgroup2 = 3
1,2,3 vs 4,5,6
1,2,4 vs 3,5,6
Size Subgroup1 = 4, Subgroup2 = 2
Size Subgroup1 = 5, Subgroup2 = 1
I have searched for a solution but I haven´t found one yet. Thanks!
Stephan

1 件のコメント

Andrea Ferrari Braga
Andrea Ferrari Braga 2012 年 9 月 26 日
編集済み: Andrea Ferrari Braga 2012 年 9 月 26 日
Hi, I'm searching for the solution of this problem too.
Do you find anything useful in this months ?
Thanks.
Andrea

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

 採用された回答

Matt Fig
Matt Fig 2012 年 9 月 26 日
編集済み: Matt Fig 2012 年 9 月 26 日
This might be what you are looking for:
>> C = partitions(4);
>> partdisp(C)
The 15 partitions of set {1 2 3 4}:
{1 2 3 4}
{1 2 3} {4}
{1 2 4} {3}
{1 2} {3 4}
{1 2} {3} {4}
{1 3 4} {2}
{1 3} {2 4}
{1 3} {2} {4}
{1 4} {2 3}
{1} {2 3 4}
{1} {2 3} {4}
{1 4} {2} {3}
{1} {2 4} {3}
{1} {2} {3 4}
{1} {2} {3} {4}

その他の回答 (1 件)

drawer
drawer 2012 年 9 月 26 日

0 投票

Thanks for your responses. I found a solution, but it is too embarassing to post it since there is also a very easy way to solve the problem. thanks again!

1 件のコメント

James
James 2012 年 10 月 1 日
You sound an awful lot like Fermat here. :-)

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

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2012 年 7 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by