MATLAB: How to vector-multiply two arrays of matrices?
I have two 3-dimensional arrays, the first two dimensions of which represent matrices and the last one counts through a parameterspace, as a simple example take A = repmat([1,2; 3,4], [1 1 4]); (but assume A(:,:,j) is different for each j ). How can one easily perform a per- j matrix multiplication of two such matrix-arrays A and B ? C = A; % pre-allocate, nan(size(A,1), size(B,2)) would be better but slower for jj = 1:size(A, 3) C(:,:,jj) = A(:,:,jj) * B(:,:,jj); end certainly does the job, but if the third dimension is more like 1e3 elements this is very slow since it doesn't use MATLAB's