All the posible combination of two matrices

1 回表示 (過去 30 日間)
Jothi
Jothi 2012 年 12 月 17 日
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 日
C = [];
for j1 = 1:numel(B)
a = nchoosek(B,j1);
C = [C;num2cell([repmat(A,size(a,1),1),a],2)];
end
  3 件のコメント
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 日
You cannot create a numeric matrix with a variable number of elements in each row.
  4 件のコメント
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()

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by