MATLAB: Do I receive the error “Index exceeds matrix dimensions.” when I try to compile the file using the MEX function

atMATLABmexscriptsignswitch

I am trying to create a MEX-file.
I am trying to compile my code by issuing the following command at the MATLAB command prompt:
 
mex @myDirectory\myFile.c
When I issue this command, I receive the following error:
  ERROR: ??? Index exceeds matrix dimensions. Error in ==> mex>get_mex_opts at 351 arg = varargin{count}; Error in ==> mex at 225 mexname = get_mex_opts(varargin{:});
Why am I receiving this error?

Best Answer

You are receiving this error because "myDirectory" starts with an "@" symbol which causes the MEX function to interpret "myDirectory" as a script switch.
The "@" symbol is a MEX script switch which, when followed by a file name, tells the MEX function to include the contents of the text file as command line arguments to the mex script. For more information on MEX Script Switches, see the online documentation at:
To use the MEX function with directories that begin with "@", precede the directory name with ".\".
In the example that you have cited here, use the following syntax instead:
 
mex .\@myDirectory\myFile.c