Borrar filtros
Borrar filtros

How can I power the elements of a 3D matrix to the elements of 2D matrix?

2 visualizaciones (últimos 30 días)
Dear All, I have two cells arrays which contains matrices. In one of the cell array are 3D matrices and in the other one are 2D matrices. I would like to power the elements of 3D matrices to the elements of 2D matrices. I tried to solve by the following code:
for jj=1:360;
bb=B{jj};
for kk=2:360;
m=out_m{kk};
for i=1:464;
for j=1:201;
for k=1:size(m,3);
P(i,j,k)=m(i,j,k).^bb(i,j);
PP{jj,1}=P;
end
end
end
end
end
It is very slow. Could someone suggest me a better method?

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 23 de Abr. de 2015
Editada: Azzi Abdelmalek el 23 de Abr. de 2015
a=randi(10,4,3,2)
b=randi(10,4,3)
out=bsxfun(@power,a,b)

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 23 de Abr. de 2015
Editada: Andrei Bobrov el 23 de Abr. de 2015
Let you data is arrays B and out_m :
B={};
out_m = {};
for jj = 1:3
out_m{jj} = randi(6,2,3,4);
B{jj} = randi(5,2,3);
end
solution:
bb = cat(4,B{:});
m = cat(4,out_m{:});
P = bsxfun(@power,m,bb);
PP = reshape(num2cell(P,[1 2 3]),[],1);

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by