2D matrix multiply with 3D array
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Qiu Xu
el 23 de Oct. de 2021
Comentada: Qiu Xu
el 24 de Oct. de 2021
Hi,
I have two 2D matrix u and v, and a 3D array B. I want to perform the following calculations, for example
u=rand(200,300);
v=rand(200,300);
B=rand(60,60,300)
c=0;
for j=1:300
u1=0;
v1=0;
for k=1:200
u1=u1+u(k,j)*B(:,:,k);
v1=v1+v(k,j)*B(:,:,k);
end
c=c+u1.*v1;
end
Due to two for loops, it is very slowly for the larger matrix u, v and B. Are there some good methods to compute c without using any for loop?.
Thanks a lot.
1 comentario
Matt J
el 23 de Oct. de 2021
Are you sure the size of B shouldn't be 60x60x200? If not, your code example ignores the final 100 pages of B.
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Multidimensional Arrays 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!