Create matrix from combination of two other matrices
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuesta aceptada
Andrei Bobrov
el 11 de Mayo de 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 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!