All the posible combination of two matrices

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]
how to find it

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 12월 17일
편집: Andrei Bobrov 2012년 12월 17일

0 개 추천

C = [];
for j1 = 1:numel(B)
a = nchoosek(B,j1);
C = [C;num2cell([repmat(A,size(a,1),1),a],2)];
end

댓글 수: 3

Andrei Bobrov
Andrei Bobrov 2012년 12월 17일
I am corrected.
Jothi
Jothi 2012년 12월 17일
I got the results it's working properly
Jothi
Jothi 2012년 12월 17일
How to store this in xls file.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 12월 17일

0 개 추천

You cannot create a numeric matrix with a variable number of elements in each row.

댓글 수: 4

Jothi
Jothi 2012년 12월 17일
then how to get that result sir.
Walter Roberson
Walter Roberson 2012년 12월 17일
You cannot get the result you asked for. Andrei's answer does not give you the result you asked for: it gives you a cell array, but you asked for a numeric array.
Jothi
Jothi 2012년 12월 17일
yes sir I did not get the numeric array. but cell array is okay for my problem. but how to store these answers (cell array) in xls file.
Walter Roberson
Walter Roberson 2012년 12월 17일
xlswrite()

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

질문:

2012년 12월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by