You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: tensor_nmodeproduct.m
    path of file: ./repos/mtt
    
    the code of the file until where you have to start completion: %% n-Mode Tensor - Matrix Product
% http://www.mathworks.com/matlabcentral/fileexchange/24268-n-mode-tensor-matrix-product
%
function B = tensor_nmodeproduct(A,M,n)
%
% Calculates the n-Mode Product of a Tensor A and a Matrix M
% 
% B = nmodeproduct(A,M,n)
% 
% B = A (x)_n M .. According to the Definition in De Lathauwer (2000)
%
% with:
% A:    (I_1 x I_2 x .. I_n x .. I_N) .. ->  n is in [1..N]
% M:    (J   x I_n)
% B:    (I_1 x I_2 x 
    
function B = tensor_nmodeproduct(A,M,n)
%
% Calculates the n-Mode Product of a Tensor A and a Matrix M
% 
% B = nmodeproduct(A,M,n)
% 
% B = A (x)_n M .. According to the Definition in De Lathauwer (2000)
%
% with:
% A:    (I_1 x I_2 x .. I_n x .. I_N) .. ->  n is in [1..N]
% M:    (J   x I_n)
% B:    (I_1 x I_2 x .. J x   .. I_N)
%
% note: "(x)_n" is the operator between the tensor and the matrix
% 
% v0.001 2009 by Fabian Schneiter
% 

% check inputs:
dimvec = size(A);
n = fix(n);
if (length(dimvec)<n || n<1)
    error('nmodeproduct: n is not within the order range of tensor A ');
end