AllCombinations = {1 2 3 4 5 [1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [2 5] [3 4] [3 5] [4 5] [1 2 3] [1 2 4] [1 2 5] [1 3 4] [1 3 5] [1 4 5] [2 3 4] [2 3 5] [2 4 5] [3 4 5] [1 2 3 4] [1 2 3 5] [1 2 4 5] [1 3 4 5] [2 3 4 5] [1 2 3 4 5] }A =[num2cell(combnk(1:5, 1),2)' [num2cell(combnk(1:5, 2),2)'[num2cell(combnk(1:5, 3),2)'[num2cell(combnk(1:5, 4),2)'[num2cell(combnk(1:5, 5),2)']
Goal:
AllCombinations = {1 2 3 4 5 [1 2] [1 3] [1 4] [1 5] [2 3] [2 4] [2 5] [3 4] [3 5] [4 5] [1 2 3] [1 2 4] [1 2 5] [1 3 4] [1 3 5] [1 4 5] [2 3 4] [2 3 5] [2 4 5] [3 4 5] [1 2 3 4] [1 2 3 5] [1 2 4 5] [1 3 4 5] [2 3 4 5] [1 2 3 4 5] }
generate a cell array which is similair to this, but without entering the values manually
I have a set [1 2 3 4 5] and I have to generate all possible combinations and put it in a cell array, such that comk{6} returns [1 2]. Hence order is also important.
I personally thought about using a loop to get something like this, but i am not sure how the loop should be constructed.
A =[num2cell(combnk(1:5, 1),2)' ..... [num2cell(combnk(1:5, 5),2)']
Best Answer