Multiply two 3D arrays that result would be 4D
Show older comments
Hello to All,
I am trying to work and understand 4D arrays. Lets say I have two 3D gpuArrays a(100x5x5) and b(5x5x5). I would like to multiply them that it would result in 4D array c(100x5x5x5), and example of multiplication:
For j=1:5
For i=1:5
c(:,:,i,j)=a(:,i,j)*b(i,:,j)
end
end
What would be the way to achieve this. I am trying to go for 4D arrays, because I would like to avoid for loops.
2 Comments
James Tursa
on 13 Jul 2018
a(:,i,j) is a 100x1. b(i,:,j) is a 1x5. So the result of a matrix multiply is going to be a 100x5. This would mean you need c(:,:,i,j) instead of c(:,i,j) on the lhs. Is this what you want to do?
Mantas Vaitonis
on 13 Jul 2018
Accepted Answer
More Answers (1)
Matt J
on 13 Jul 2018
c=a.*permute(b,[4,1,3,2]);
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!