All the posible combination of two matrices more than 40 elements

1 Ansicht (letzte 30 Tage)
Jothi
Jothi am 20 Dez. 2012
I have two matrix
A=[1]
and
B=[2 3 4]
find the all possible combination of these tow matrices is
the output
C=[1 2; 1 3; 1 4; 1 2 3; 1 2 4; 1 3 4; 1 2 3 4]
I got the answer in form of cell array using following code
C = [];
for j1 = 1:numel(B)
a = nchoosek(B,j1);
C = [C;num2cell([repmat(A,size(a,1),1),a],2)];
end
But I have more than 40 elements in the Matrix B.
ncoosek works only 15 elements.
How to find the combinations of more than 40 elements.

Antworten (1)

Jan
Jan am 20 Dez. 2012
Whenever combinations or permutations of a set of more than 10 elements is wanted, it is strongly recommended to calculate the size of the output at first. Usually the problem appears to be too large to be hold at once in the memory.
The limitation of nchoosek to 15 elements has a good reason, so this should let you think twice.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by