Create matrix from combination of two other matrices
3 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Andrei Bobrov
on 11 May 2012
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 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!