Thread Subject:
Is there a way to tell when a warning happens?

Subject: Is there a way to tell when a warning happens?

From: Pat Finder

Date: 28 Jun, 2013 16:29:22

Message: 1 of 4

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?
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?

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... ;-) ]

Subject: Is there a way to tell when a warning happens?

From: Pat Finder

Date: 28 Jun, 2013 17:16:07

Message: 2 of 4

% Okay, so this works, but seems clumsy:
lastwarn('none');
% Processing here...
checkForWarning = lastwarn();
if ( strcmp(checkForWarning,'none') ~= 1 )
    % Test for poorly conditioned matrices:
   validity = 0;
end

Better insights appreciated.

Subject: Is there a way to tell when a warning happens?

From: Doug Schwarz

Date: 28 Jun, 2013 18:09:42

Message: 3 of 4

In article <kqkgcn$lbd$1@newscl01ah.mathworks.com>,
 "Pat Finder" <pfinder@netacc.net> wrote:

> % Okay, so this works, but seems clumsy:
> lastwarn('none');
> % Processing here...
> checkForWarning = lastwarn();
> if ( strcmp(checkForWarning,'none') ~= 1 )
> % Test for poorly conditioned matrices:
> validity = 0;
> end
>
> Better insights appreciated.

Hi "Pat",

Something very much like that (essentially identical) is what I did in
my intersections.m. It was the best I could come up with.

Doug

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: Is there a way to tell when a warning happens?

From: Steven_Lord

Date: 1 Jul, 2013 14:48:52

Message: 4 of 4



"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

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
warning error Pat Finder 28 Jun, 2013 16:29:24
rssFeed for this Thread

Contact us