If A is a true 3D array, something like A = rand(4,10,3) and it is assumed that B remains as a 2D array, then each A(:,:,1)*B A = rand(4,10,3) A(:,:,1)*B will give a 2D array .
So, assuming you want to store these 2D arrays as slices in the third dimension of the output array, C also -
C(:,:,1) = A(:,:,1)*B; C(:,:,2) = A(:,:,2)*B; C(:,:,3) = A(:,:,3)*B; and so on.
To solve this in a vectorized way, one approach would be to use reshape A in a 2D array combining the first and third dimensions and then performing matrix multiplication. Finally, so that the size of the output is the same as the previous one specified by C , we need the last stage of the change.
The implementation will look something like this:
%
Run Example -
>> A = rand(4,10,3); B = rand(10,16); C(:,:,1) = A(:,:,1)*B; C(:,:,2) = A(:,:,2)*B; C(:,:,3) = A(:,:,3)*B; >> [m,n,r] = size(A); out = permute(reshape(reshape(permute(A,[1 3 2]),[],n)*B,m,r,[]),[1 3 2]); >> all(C(:)==out(:)) %
According to comments , if A is a three-dimensional array with always a singlet dimension at the beginning, you can simply use squeeze and then matrix multiplication like this:
C = B.'*squeeze(A)