Combine two different matrices to create one new matrix of all matrix combinations
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I have the following matrices
WT_energy_supply(:,:,M) and PV_power_output(:,:,K)
which are 365 x 24 matrices and M = 3 and K = 10. Therefore there are 30 possible combinations of WY_energy_supply and PV_power_output. I am looking to create a set of matrices (in the form (:,:,Z)) that add corresponding elements in each matrix to form this new set (again 365x24 with 30 different matrices) Does anyone have any idea where to start coding this?
Thank you
0 comentarios
Respuesta aceptada
Sean de Wolski
el 11 de Mayo de 2012
Nice brain teaser!
%Sample data:
A = ones(4,4,5);
B = bsxfun(@times,ones(4,4,3),cat(3,1,2,3));
%Nice to know:
sz = size(B);
%Engine:
C = reshape(bsxfun(@plus,A, reshape(B,sz(1),sz(2),1,sz(3))),sz(1),sz(2),[]);
18 comentarios
Más respuestas (2)
Andrei Bobrov
el 11 de Mayo de 2012
eg:
M = 3;
K = 10;
WT_energy_supply = randi(10,10,4,M);
PV_power_output = randi([10 50],10,4,K);
%solution
ij = fullfact([M K]);
out = WT_energy_supply(:,:,ij(:,1)) + PV_power_output(:,:,ij(:,2)) ;
5 comentarios
Sean de Wolski
el 11 de Mayo de 2012
That's what bsxfun does for you!
think about it, how can you add two things that are different sizes?
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!