how interrupt after warning message?

  • Follow


warning messages usually don't interrupt the simulation of a script in matlab, but I need to do it. Specifically I need to interrupt my simulations after the message 'Warning: Matrix is singular to working precision'. How can I do it? Is there a condition 'if warning' o something similar?
0
Reply Niccolo 5/14/2010 12:50:21 PM

Not sure, but you may want to have a look at  the command dbstop

"Niccolo' Bulgarini" <n.bulgarini@gmail.com> wrote in message <hsjgud$8i8$1@fred.mathworks.com>...
> warning messages usually don't interrupt the simulation of a script in matlab, but I need to do it. Specifically I need to interrupt my simulations after the message 'Warning: Matrix is singular to working precision'. How can I do it? Is there a condition 'if warning' o something similar?
0
Reply Fabio 5/14/2010 12:59:04 PM


"Niccolo' Bulgarini" <n.bulgarini@gmail.com> wrote in message 
news:hsjgud$8i8$1@fred.mathworks.com...
> warning messages usually don't interrupt the simulation of a script in 
> matlab, but I need to do it. Specifically I need to interrupt my 
> simulations after the message 'Warning: Matrix is singular to working 
> precision'. How can I do it? Is there a condition 'if warning' o something 
> similar?

When you say "interrupt" do you mean "enter debug mode" or do you mean 
"abort the execution of my function"?

If the former, use DBSTOP -- it has an option that tells MATLAB to stop 
whenever a warning is thrown.

If the latter, check LASTWARN after your calculation that may involve a 
singular matrix and use ERROR if the warning or warnings that you're looking 
for have occurred.

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ 


0
Reply Steven 5/14/2010 1:14:19 PM

I've realized I've to do it harder: I should break a loop generated by a p-file. I'm using an optimization algorithm and a nuber is close to singular or bad scaled. since I've no access to the p-file, can I give a command before calling the p-file for breaking from that loop once a waring is encountered?

many thanks!

"Steven Lord" <slord@mathworks.com> wrote in message <hsjiba$aio$1@fred.mathworks.com>...
> 
> "Niccolo' Bulgarini" <n.bulgarini@gmail.com> wrote in message 
> news:hsjgud$8i8$1@fred.mathworks.com...
> > warning messages usually don't interrupt the simulation of a script in 
> > matlab, but I need to do it. Specifically I need to interrupt my 
> > simulations after the message 'Warning: Matrix is singular to working 
> > precision'. How can I do it? Is there a condition 'if warning' o something 
> > similar?
> 
> When you say "interrupt" do you mean "enter debug mode" or do you mean 
> "abort the execution of my function"?
> 
> If the former, use DBSTOP -- it has an option that tells MATLAB to stop 
> whenever a warning is thrown.
> 
> If the latter, check LASTWARN after your calculation that may involve a 
> singular matrix and use ERROR if the warning or warnings that you're looking 
> for have occurred.
> 
> -- 
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ 
> 
0
Reply Niccolo 5/14/2010 2:03:07 PM

Dear Niccolo!

> I've realized I've to do it harder: I should break a loop generated by a p-file. I'm using an optimization algorithm and a nuber is close to singular or bad scaled. since I've no access to the p-file, can I give a command before calling the p-file for breaking from that loop once a waring is encountered?

P-files can be easily influenced by creating M-files with the called subfunctions in the same directory. So if your warning is created e.g. in the function LU, create a new file called "lu.m" in the same directory as your P-file:

----------------------------------------
% Please adjust the number of outputs etc to your special problem.
function [L, U, P, Q] = lu(varargin)
[L, U, P, Q] = builtin('lu', varargin{:});
if ~isempty(lastwarn)
  error(lastwarn);
end
-----------------------------------------

Then you can enclose the call to your optimization in a TRY CATCH block.
Use this to find the function which causes the warning:
  dbstop if warning

Good luck, Jan
0
Reply Jan 5/14/2010 2:24:05 PM

"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hsjme5$d8h$1@fred.mathworks.com>...
> Dear Niccolo!
> 
> > I've realized I've to do it harder: I should break a loop generated by a p-file. I'm using an optimization algorithm and a nuber is close to singular or bad scaled. since I've no access to the p-file, can I give a command before calling the p-file for breaking from that loop once a waring is encountered?
> 
> P-files can be easily influenced by creating M-files with the called subfunctions in the same directory. So if your warning is created e.g. in the function LU, create a new file called "lu.m" in the same directory as your P-file:
> 
> ----------------------------------------
> % Please adjust the number of outputs etc to your special problem.
> function [L, U, P, Q] = lu(varargin)
> [L, U, P, Q] = builtin('lu', varargin{:});
> if ~isempty(lastwarn)
>   error(lastwarn);
> end
> -----------------------------------------
> 
> Then you can enclose the call to your optimization in a TRY CATCH block.
> Use this to find the function which causes the warning:
>   dbstop if warning
> 
> Good luck, Jan

good stuff... yet, it does not completely solve the OP's problem as he/she still does not get access to the built-in...

us
0
Reply us 5/14/2010 2:47:04 PM

another problem is that I receive this message:

Warning: Matrix is singular to working precision. 
> In /home ... optim/optim/private/backsolveSys.p>backsolveSys at 11
  In /home ...optim/optim/private/solveKKTsystem.p>solveKKTsystem at 9
  In /home ...optim/optim/private/computeTrialStep.p>computeTrialStep at 60
  In /home ...optim/optim/barrier.p>barrier at 275

so I don't know neither which input & output arguments has the backsolveSys.p function!




"us " <us@neurol.unizh.ch> wrote in message <hsjnp8$btk$1@fred.mathworks.com>...
> "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message <hsjme5$d8h$1@fred.mathworks.com>...
> > Dear Niccolo!
> > 
> > > I've realized I've to do it harder: I should break a loop generated by a p-file. I'm using an optimization algorithm and a nuber is close to singular or bad scaled. since I've no access to the p-file, can I give a command before calling the p-file for breaking from that loop once a waring is encountered?
> > 
> > P-files can be easily influenced by creating M-files with the called subfunctions in the same directory. So if your warning is created e.g. in the function LU, create a new file called "lu.m" in the same directory as your P-file:
> > 
> > ----------------------------------------
> > % Please adjust the number of outputs etc to your special problem.
> > function [L, U, P, Q] = lu(varargin)
> > [L, U, P, Q] = builtin('lu', varargin{:});
> > if ~isempty(lastwarn)
> >   error(lastwarn);
> > end
> > -----------------------------------------
> > 
> > Then you can enclose the call to your optimization in a TRY CATCH block.
> > Use this to find the function which causes the warning:
> >   dbstop if warning
> > 
> > Good luck, Jan
> 
> good stuff... yet, it does not completely solve the OP's problem as he/she still does not get access to the built-in...
> 
> us
0
Reply Niccolo 5/14/2010 3:30:22 PM

Dear Urs!

> > P-files can be easily influenced by creating M-files with the called subfunctions in the same directory. So if your warning is created e.g. in the function LU, create a new file called "lu.m" in the same directory as your P-file:
> > 
> > ----------------------------------------
> > % Please adjust the number of outputs etc to your special problem.
> > function [L, U, P, Q] = lu(varargin)
> > [L, U, P, Q] = builtin('lu', varargin{:});
> > if ~isempty(lastwarn)
> >   error(lastwarn);
> > end
> > -----------------------------------------
> > 
> > Then you can enclose the call to your optimization in a TRY CATCH block.
> > Use this to find the function which causes the warning:
> >   dbstop if warning
> > 
> > Good luck, Jan
 
> good stuff... yet, it does not completely solve the OP's problem as he/she still does not get access to the built-in...
> 
> us

Correct! Damn, I'm still thinking in Matlab 6.5, where built-in's are called instead of functions in the local directory.

For Matlab 2009a I find this behaviour:
I create test.m in a folder in the Matlab path:
% File D:\MFiles\test.m --------------------
function [L, U] = test(X)
which('lu')
[L, U] = lu(X);
% --------------------

% File D:\MFiles\lu.m --------------------
function [L, U] = lu(X)
disp('my lu')
[L, U] = builtin('lu', X);
% ---------------------

The WHICH command replies correctly:
  D:\MFiles\lu.m
but it does not call the local lu! "my lu" does not appear in the command window. When I make this folder the current directory, a warning appears, that "the same name exists as a MATLAB builtin". But my local lu is not called neither after cd('D:\MFiles') nor after cd(elsewhere).
Moving D:\MFiles to the initial position in the path does not help. 
This is conform with the documentation, because lu is an overloaded function for @double and @single, and overloaded function have the precedence 5, M-files in the current directory come at position 6, and M-files on the path and built-in's at the last position 7.

E.g. STRCMP in the same folder *is* called instead of Matlab's builtin function. If you create a @char/strcmp.m anywhere in the path, then the local STRCMP is not called anymore!

Then I tried moving the personal lu to the subfolder D:\MFiles\private\ and it works as expected and wanted: "test" calls \private\lu, \private\lu calls built-in lu. Private functions have the precedence 3...
This private\ method allows bypassing all functions (except for the 20 keywords - see ISKEYWORD) called by P-files and this is the cause for the very limited privacy/security level of the P-coding. 

@OP: Please create the man-in-the-middle-attack function in a the subfolder private\ . Or ask the author to ship the M-file.

Jan
0
Reply Jan 5/14/2010 4:34:05 PM

7 Replies
181 Views

(page loaded in 0.046 seconds)

Similiar Articles:













7/24/2012 1:56:31 PM


Reply: