Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

exit matlab when running batch m file

575 views
Skip to first unread message

Gregory

unread,
Mar 25, 2009, 10:30:21 AM3/25/09
to
I'm currently running some .m files using the -r flag from the command line. This is all in batch mode, so I have a program that periodically calls matlab and passes an m file to run. It runs the file and then exits normally.
This all works fine except when there is an error in the file being run. Then matlab displays the error on the console and doesn't exit... it just waits for user input to type exit at the matlab command line.
It would be very difficult to add try/catch code to the .m file being run because the error is actually occuring in an .m file thats not accessible to me to fix.

Is there a way to just automatically exit matlab if an error occurs? Or something like resume on error?

Steven Lord

unread,
Mar 25, 2009, 1:19:47 PM3/25/09
to

"Gregory " <ju...@junk.org> wrote in message
news:gqdf5t$666$1...@fred.mathworks.com...

Note that when you use -r, you can include multiple statements to be
executed by putting them in double quotes.

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/f8-4994.html

The command [matlab -r "try, unmodifiableCodeThatMayError, catch,
handleTheError, end, exit"] should do what you want (for appropriate values
of unmodifiableCodeThatMayError and handleTheError, of course.)

--
Steve Lord
sl...@mathworks.com


Gregory

unread,
Mar 25, 2009, 3:21:01 PM3/25/09
to
Thank you!

"Steven Lord" <sl...@mathworks.com> wrote in message <gqdp2u$4q2$1...@fred.mathworks.com>...

0 new messages