Thread Subject: an exit(0) function

Subject: an exit(0) function

From: Chris

Date: 13 Jan, 2011 23:05:51

Message: 1 of 11

Hey, Is there some way in Matlab to use a C-style exit(0) function? The reason I ask, is I want to be able to break out of nested functions without displaying anything on the command line (as assert and error both do),

Thanks!

Subject: an exit(0) function

From: Matt Fig

Date: 13 Jan, 2011 23:25:04

Message: 2 of 11

Chris <skynet414@gmail.com> wrote in message <2071624916.24176.1294959981193.JavaMail.root@gallium.mathforum.org>...
> Hey, Is there some way in Matlab to use a C-style exit(0) function? The reason I ask, is I want to be able to break out of nested functions without displaying anything on the command line (as assert and error both do),
>
> Thanks!

I am not a C expert, but I suspect the RETURN function could do what you want.

Subject: an exit(0) function

From: I am too much me

Date: 14 Jan, 2011 00:53:00

Message: 3 of 11

On 13/01/11 5:25 PM, Matt Fig wrote:
> Chris <skynet414@gmail.com> wrote in message
> <2071624916.24176.1294959981193.JavaMail.root@gallium.mathforum.org>...
>> Hey, Is there some way in Matlab to use a C-style exit(0) function?
>> The reason I ask, is I want to be able to break out of nested
>> functions without displaying anything on the command line (as assert
>> and error both do),
>>
>> Thanks!
>
> I am not a C expert, but I suspect the RETURN function could do what you
> want.

No, exit(0) corresponds to quit(). Yes, that does quit the matlab
session entirely, but then exit(0) in C ends execution of the executable
entirely and there is no equivalent in C to "return to the main
function" (though there the C setjump() longjump() )

Subject: an exit(0) function

From: Husam Aldahiyat

Date: 14 Jan, 2011 06:31:05

Message: 4 of 11

There is no such thing as exit(0) in MATLAB. I've searched for two months for such a command with no results, and I'm 99% sure about it.

Subject: an exit(0) function

From: Husam Aldahiyat

Date: 14 Jan, 2011 06:32:05

Message: 5 of 11

Chris <skynet414@gmail.com> wrote in message <2071624916.24176.1294959981193.JavaMail.root@gallium.mathforum.org>...
> Hey, Is there some way in Matlab to use a C-style exit(0) function? The reason I ask, is I want to be able to break out of nested functions without displaying anything on the command line (as assert and error both do),
>
> Thanks!

Subject: an exit(0) function

From: I am too much me

Date: 14 Jan, 2011 06:46:38

Message: 6 of 11

On 14/01/11 12:31 AM, Husam Aldahiyat wrote:
> There is no such thing as exit(0) in MATLAB. I've searched for two
> months for such a command with no results, and I'm 99% sure about it.

quit() is a pretty close approximation. You can't control the return
status, though.

Subject: an exit(0) function

From: Chris

Date: 14 Jan, 2011 11:57:43

Message: 7 of 11

It seems there is no such function, anyone have ideas on how I could create my own exit() function? I can't seem to find the source for quit() and error() which is annoying.

Also I found a bug in mlint after creating the script

disp(123)
quit cancel
disp(456)

MLint gives the warning that the disp(456) line can't be reached, but running the script prints 456!

Subject: an exit(0) function

From: Bruno Luong

Date: 14 Jan, 2011 12:47:04

Message: 8 of 11

Chris <skynet414@gmail.com> wrote in message <2071624916.24176.1294959981193.JavaMail.root@gallium.mathforum.org>...
> Hey, Is there some way in Matlab to use a C-style exit(0) function? The reason I ask, is I want to be able to break out of nested functions without displaying anything on the command line (as assert and error both do),
>

Why not use TRY/CATCH in the main function, rethrows the error if a real error occurs, and simply returns if the dummy error is detected.

Bruno

Subject: an exit(0) function

From: Bruno Luong

Date: 14 Jan, 2011 12:53:04

Message: 9 of 11

"Husam Aldahiyat" wrote in message <igoqj8$hnq$1@fred.mathworks.com>...
> There is no such thing as exit(0) in MATLAB. I've searched for two months for such a command with no results, and I'm 99% sure about it.

I have a project idea for you Husam. Extend your GOTO emulator to be able to jump any point to to another m file.

GOTO anothermfile:labelx;

Bruno

Subject: an exit(0) function

From: Steven_Lord

Date: 14 Jan, 2011 15:51:27

Message: 10 of 11



"Chris" <skynet414@gmail.com> wrote in message
news:777612481.26978.1295006293276.JavaMail.root@gallium.mathforum.org...
> It seems there is no such function, anyone have ideas on how I could
> create my own exit() function? I can't seem to find the source for quit()
> and error() which is annoying.

Those are built-in functions implemented in the source code for MATLAB, and
we do not share the source code for MATLAB.

> Also I found a bug in mlint after creating the script
>
> disp(123)
> quit cancel
> disp(456)
>
> MLint gives the warning that the disp(456) line can't be reached, but
> running the script prints 456!

Yes, this does seem like Code Analyzer assumes that anything after a call to
QUIT is unreachable and didn't take into account the 'cancel' input. Still,
you shouldn't be using "quit cancel" anywhere but your finish.m file, as it
doesn't do anything when used outside finish.m as per the documentation.

http://www.mathworks.com/help/techdoc/ref/quit.html

I'll note that to the development staff.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlab.wikia.com/wiki/FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: an exit(0) function

From: Husam Aldahiyat

Date: 16 Feb, 2011 15:45:04

Message: 11 of 11

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <igpgvg$9ji$1@fred.mathworks.com>...
> "Husam Aldahiyat" wrote in message <igoqj8$hnq$1@fred.mathworks.com>...
> > There is no such thing as exit(0) in MATLAB. I've searched for two months for such a command with no results, and I'm 99% sure about it.
>
> I have a project idea for you Husam. Extend your GOTO emulator to be able to jump any point to to another m file.
>
> GOTO anothermfile:labelx;
>
> Bruno

Not even close. Next update will allow a jump to a label in another code written in another language.

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

Contact us at files@mathworks.com