|
"Pat Finder" <pfinder@netacc.net> wrote in message
news:kqkdl2$e3j$1@newscl01ah.mathworks.com...
> Instead of explicitly checking for singular matrices, and other things
> that cause warning messages, it would be convenient to write the code so
> that it just runs, but IF a warning occurs, I can test it and take
> corrective actions.
>
> Questions:
> Is there a way to tell if any warning has occurred?
Yes, LASTWARN.
> The same could be asked about errors, but they just stop the program.
>
> Does the answer to the question have to do with the lastwarn() command?
Yes.
lastwarn(''); % Reset the last warning state
codeThatMayIssueWarning;
[warnmsg, warnid] = lastwarn;
if ~isempty(warnmsg)
% handle issued warning
end
Alternately, if you know what condition(s) will cause the warning to be
issued, you could check those conditions ahead of time.
if isreal(x) && isreal(y)
plot(x, y);
else
plot(real(x), real(y));
end
> Does anyone have an example that might help me write this loop:
>
> for counter=1: lots of thing
> do some processing
> if a warning occurred
> disp('set a break here and see what to do, or test
> for singularity...');
> end
> end
>
>
> Thanks for your expertise.
>
>
> [no, this is not for homework... ;-) ]
--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
|