Create matrix from combination of two other matrices

3 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Sparse Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by