All the posible combination of two matrices more than 40 elements
1 回表示 (過去 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 件のコメント
回答 (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!