From: Niccolo' Bulgarini on
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?
From: Fabio Pinna on
Not sure, but you may want to have a look at the command dbstop

"Niccolo' Bulgarini" <n.bulgarini(a)gmail.com> wrote in message <hsjgud$8i8$1(a)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?
From: Steven Lord on

"Niccolo' Bulgarini" <n.bulgarini(a)gmail.com> wrote in message
news:hsjgud$8i8$1(a)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(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Niccolo' Bulgarini on
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(a)mathworks.com> wrote in message <hsjiba$aio$1(a)fred.mathworks.com>...
>
> "Niccolo' Bulgarini" <n.bulgarini(a)gmail.com> wrote in message
> news:hsjgud$8i8$1(a)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(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
From: Jan Simon on
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