$\begingroup$
Want to multiply a $3D$ matrix $A$ of size $n$ x $m$ x $p$, ($n$: number of raws, $m$: number of columns and $p$: number of slices), by a 2D matrix $B$ of size $m$ x 1 x $p$. The results as shown in the figure below is a matrix $C$ of size $n$ x 1 x $p$. How to perform this on Matlab without using loops ?
$\endgroup$ 11 Answer
$\begingroup$Not sure it is the good place for asking such question. I suppose that you want to compute the output matrix $\mathbf{C}$ as
C(:,:,p)=A(:,:,p)*B(:,:,p) using the matrix product. You can easily do this using implicit broadcasting
C = sum(A.*permute(B,[2,1,3]),2) $\endgroup$