MATLAB: Do I receive an error when I execute an M-file in the Linux shell using the -r flag in MATLAB 7.11 (R2010b)

batchcommandconsoledosMATLABpromptscriptshell

I have a function which executes without errors in MATLAB. However, when I try to execute it in the Linux shell using the following code (which contains the -r flag), I receive an error and have to type "exit" to quit the program.
matlab -r myfile.m

Best Answer

Remove remove the ".m" extension from the function name after the -r flag.
Explanation: When using matlab with the “-r” flag, the subsequent argument is interpreted as a MATLAB command, not as an input filename. It is the same as if you were directly typing the commands after “-r” into the MATLAB command prompt. For example, if you wish to execute a file called “myfile.m”, the MATLAB command “myfile” runs the file. With the “.m” extension, it treats the function as if it returns a structure and then attempts to access the “m” field of that structure. A warning first occurs because the programming practice is deprecated, then an error occurs because the function actually does not return a structure object.