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

2 views (last 30 days)
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

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 12 Apr 2012
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.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2010b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!