Create matrix from combination of two other matrices

3 ビュー (過去 30 日間)
Andrew Alkiviades
Andrew Alkiviades 2012 年 5 月 11 日
Hi
I have two types of matrices that I need to add together. One has 5 (365x24) matrices and the other has 10 (365x24) matrices. I am trying to create a third matrix that has all the possible combinations of a sum of two types above. Therefore I need to code to create 50 matrices (again 365x24) that sums both elements in the same position
Does anyone have any idea where to start?
Thank you

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 5 月 11 日
eg:
Mtype1 = arrayfun(@(ii)randi(randi([5 10]),5),(1:5).','un',0);
Mtype2 = arrayfun(@(ii)randi(randi([10 50]),5),(1:10).','un',0);
% solution
[ii,jj] = ndgrid(1:numel(Mtype1),1:numel(Mtype2));
out = cellfun(@(x,y)x + y,Mtype1(ii(:)),Mtype2(jj(:)),'un',0);
or:
ij = fullfact([5 10]);
out = cellfun(@(x,y)x + y,Mtype1(ij(:,1)),Mtype2(ij(:,2)),'un',0);

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by