23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Warning Control<br />

Example 2 — Performing an Implicit Query<br />

Turn on one particular warning, saving the previous state of this warning<br />

in s. Remember that this nonquery syntax (where state equals on or off)<br />

performs an implicit query prior to setting the new state.<br />

s = warning('on', 'Control:parameterNotSymmetric');<br />

Restore the state of that one warning when you are ready, with<br />

warning(s)<br />

BacktraceandVerboseModes<br />

In addition to warning messages, there are two modes that can be enabled or<br />

disabled with a warning control statement. These modes are shown here.<br />

Mode Description Default<br />

backtrace<br />

verbose<br />

Display an M-stack trace<br />

after a warning is invoked.<br />

Display a message on how to<br />

suppress the warning.<br />

on (enabled)<br />

off (terse)<br />

The syntax for using this type of control statement is as follows, where state,<br />

in this case, can be only on, off, orquery.<br />

warning state mode<br />

Notethatthereisnoneedtoincludeamessage identifier with this type of<br />

control statement. All enabled warnings are affected by the this type of<br />

control statement.<br />

Example 1 — Displaying a Stack Trace on a Specific Warning<br />

It can be difficult to locate the source of a warning when it is generated<br />

from code buried in several levels of function calls. This example generates<br />

a warning within a function that is nested several levels deep within the<br />

primary function in file f1.m:<br />

function f1(a, b)<br />

for k = a:-1:b<br />

f2(k)<br />

8-23

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!