You can reshape
the stacked matrices. Suppose you have k
-by-k
matrix a
and a stack of m
k
-by-k
matrices sb
and you want the product a*sb(:,:,ii)
for ii = 1..m
. Then all you need is
sza = size(a);
b = reshape( b, sza(2), [] ); % concatenate all matrices aloong the second dim
res = a * b;
res = reshape( res, sza(1), [], size(sb,3) ); % stack back to 3d