Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: try catch /ctrl-c behaviour
Date: Tue, 1 Jun 2004 15:17:08 -0400
Organization: The MathWorks, Inc.
Lines: 43
Message-ID: <c9iknk$s3g$1@fred.mathworks.com>
References: <gC2vc.9$ri2.2@charlie.risq.qc.ca> <_D3vc.12$ri2.0@charlie.risq.qc.ca>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1086117428 28784 144.212.111.227 (1 Jun 2004 19:17:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 1 Jun 2004 19:17:08 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Xref: news.mathworks.com comp.soft-sys.matlab:209466


Guillaume wrote:
> Sorry, I answered my own question and this is quite frustrating. This
> is from Solution Number: 1-1BSWG.
>
>> In MATLAB 6.1 (R12.1), ^c will break the loop and execute the catch
>> block. In MATLAB 6.5 (R13), the catch block will not execute.
>>
>> Solution:
>>
>> TRY/CATCH no longer catches Ctrl-C interruptions as of MATLAB 6.5
>> (R13). This change in behavior was intentional. There are no known
>> workarounds for reverting to the previous behavior.
>
> So is there another way to get Matlab to, for example, pass
> intermediate results from a while loop, after hitting ctrl-c, to a
> function output?

No, but perhaps there's another way to do what you really want to do ...

> e.g. running this function, hitting ctrl-c and still get the value of
> t when I stopped it?
> %
> function t=test;
> t+0;
> while 1,
>         t=t+1;
> end
> %
>
> I want to use this to get intermediate results from an optimization.

and there is indeed another way to do what you want.  As of version 2.3 of
the Optimization Toolbox, you can specify an output function for use with
your optimizer.  By using this output function, you can specify when to stop
the optimization interactively and perform any 'cleanup'-type tasks you want
before stopping.  If you look at the Optimization Toolbox 2.3 Release Notes,
you'll see a link to an output function example.

-- 
Steve Lord
slord@mathworks.com