MATLAB: How to control the exit flag in MATLAB 7.6 (R2008a)

MATLAB

I am running MATLAB scripts from the command line using the "-r" option. If the script fails I want MATLAB to exit and return a nonzero exit flag.

Best Answer

MATLAB does not allow the user to control the exit flag.
A workaround is to enclose the entire script into a TRY/CATCH block, and in the CATCH block write to a log file. Then the subsequent shell script can read the log file which acts as a user-created "exit flag."