필터 지우기
필터 지우기

All the posible combination of two matrices more than 40 elements

조회 수: 2 (최근 30일)
Jothi
Jothi 2012년 12월 20일
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
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.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by