All the posible combination of two matrices more than 40 elements
1 view (last 30 days)
Show older comments
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.
1 Comment
Answers (1)
Jan
on 20 Dec 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.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!