All the posible combination of two matrices more than 40 elements
3 次查看(过去 30 天)
显示 更早的评论
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 个)
Jan
2012-12-20
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!