Programming |
Once you have the warning statements in your M-file code and are ready to execute the code, you can indicate how you want MATLAB to act on these warnings by issuing control statements. These statements place the specified warning(s) into a desired state and have the format
Control statements can also return information on the state of selected warnings. This only happens if you assign the output to a variable, as shown below. See Output from Control Statements.
Warning States
There are three possible values for the state
argument of a warning control statement.
State |
Description |
on |
Enable the display of selected warning message. |
off |
Disable the display of selected warning message. |
query |
Display the current state of selected warning. |
Message Identifiers
In addition to the message identifiers already discussed, there are two other identifiers that you can use in control statements only.
Identifier |
Description |
|
Set selected warning to the specified state. |
all |
Set all warnings to the specified state. |
last |
Set only the last displayed warning to the specified state. |
Note
MATLAB starts up with all warnings enabled, except for those that are displayed in response to the command, warning('query', 'all' ).
|
Example 1 -- Enabling a Selected Warning
Enable just the actionNotTaken
warning from Simulink by first turning off all warnings and then setting just that warning to on
.
Use query
to determine the current state of all warnings. It reports that you have set all warnings to off
with the exception of Simulink:actionNotTaken
.
warning query all The default warning state is 'off'. Warnings not set to the default are State Warning Identifier on Simulink:actionNotTaken
Example 2 -- Disabling the Most Recent Warning
Evaluating inv
on zero displays a warning message. Turn off the most recently invoked warning with warning off last
.
inv(0) Warning: Matrix is singular to working precision. ans = Inf warning off last inv(0) % No warning is displayed this time ans = Inf
Warning Statements | Output from Control Statements |
© 1994-2005 The MathWorks, Inc.