I have two matrices A (3,3,x) and B (3,3) where x is a variable, known value and typically on the order of thousands. I need to compute the matrix multiplication of these two, I know this can be done by
function [ out ] = mat_mult( A,B ) [~,~,np] = size(A); out = zeros(size(A)); for i=1:np out(:,:,i) = A(:,:,i)*B; endend
but I figure there is a more efficient way to do this than for loops, especially for MATLAB. Unforunately, I am not quite sure how to vectorize this.
Best Answer