Thread Subject: how to stop execution

Subject: how to stop execution

From: Todd Welti

Date: 11 Mar, 2009 21:03:00

Message: 1 of 6

This might seem like a dumb question, but how do you stop code execution? I dont mean 'return', or 'dbstop', or 'error'. I just want to stop the code immediately, with no fanfare and just return to the command line. Strangley enough, i can't seem to find a command that does this! "Return" doesn't necessarily work if the current function is not the main function. "dbstop" puts it in debug mode. "quit" quits matlab.

I've looked and looked and can't find this simple command.

Subject: how to stop execution

From: Walter Roberson

Date: 11 Mar, 2009 21:44:29

Message: 2 of 6

Todd Welti wrote:
> This might seem like a dumb question, but how do you stop code execution? I dont mean
> 'return', or 'dbstop', or 'error'. I just want to stop the code immediately, with no
> fanfare and just return to the command line.

There isn't a way: all of those routines have to be unwound and their workspaces
cleaned up, which might invoke exit handlers, and so on.

The closest I can think of is to have your main routine have a try/catch
and then when you wish to abort, error() the particular string that the
catch is keyed for, and when you detect it, bail out cleanly from your
main routine.

Subject: how to stop execution

From: Matt Fig

Date: 11 Mar, 2009 22:05:05

Message: 3 of 6

ctrl+c

Subject: how to stop execution

From: Todd Welti

Date: 11 Mar, 2009 23:50:21

Message: 4 of 6

"Matt Fig" <spamanon@yahoo.com> wrote in message <gp9cig$lul$1@fred.mathworks.com>...
> ctrl+c

I meant a command that would be in the code.

Subject: how to stop execution

From: Todd Welti

Date: 11 Mar, 2009 23:52:02

Message: 5 of 6

Walter Roberson <roberson@hushmail.com> wrote in message <XgWtl.34251$l71.6225@newsfe23.iad>...
> Todd Welti wrote:
> > This might seem like a dumb question, but how do you stop code execution? I dont mean
> > 'return', or 'dbstop', or 'error'. I just want to stop the code immediately, with no
> > fanfare and just return to the command line.
>
> There isn't a way: all of those routines have to be unwound and their workspaces
> cleaned up, which might invoke exit handlers, and so on.
>
> The closest I can think of is to have your main routine have a try/catch
> and then when you wish to abort, error() the particular string that the
> catch is keyed for, and when you detect it, bail out cleanly from your
> main routine.

Yes, that should work. is it just me or is it strange that there is not such a command - like ctrl c, but useable in an mfile?

Subject: how to stop execution

From: Jos

Date: 12 Mar, 2009 07:54:04

Message: 6 of 6

"Todd Welti" <twelti@harman.com> wrote in message <gp9ir2$kcf$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <XgWtl.34251$l71.6225@newsfe23.iad>...
> > Todd Welti wrote:
> > > This might seem like a dumb question, but how do you stop code execution? I dont mean
> > > 'return', or 'dbstop', or 'error'. I just want to stop the code immediately, with no
> > > fanfare and just return to the command line.
> >
> > There isn't a way: all of those routines have to be unwound and their workspaces
> > cleaned up, which might invoke exit handlers, and so on.
> >
> > The closest I can think of is to have your main routine have a try/catch
> > and then when you wish to abort, error() the particular string that the
> > catch is keyed for, and when you detect it, bail out cleanly from your
> > main routine.
>
> Yes, that should work. is it just me or is it strange that there is not such a command - like ctrl c, but useable in an mfile?

help keyboard

(or modify finish.m and use quit cancel)

hth
Jos

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com