MATLAB: How to multiply N dimensional matrices

matrix multiplicationn-dimensional

I am trying to multiply a 3x3xn matrix with a 3x4xn matrix.
I tried a for loop but it says that the matrix dimensions do not agree.
The new matrix that I need is just the product of the first A(:,:,i)*B(:,:,i) which should work but in my case it isn't

Best Answer

C = zeros(3,4,n) ;
for i = 1:n
C(:,:,i) = A(:,:,i)*B(:,:,i) ;
end