Programming Previous page   Next Page

Output from Control Statements

The warning function, when used in a control statement, returns a MATLAB structure array containing the previous state of the selected warning(s). Use the following syntax to return this information in structure array, s:

You must type the command using the MATLAB function format; that is, parentheses and quotation marks are required.

This example turns off divideByZero warnings for the MATLAB component, and returns the identifier and previous state in a 1-by-1 structure array.

You can use output variables with any type of warning control statement. If you just want to collect the information but don't want to change state, then simply perform a query on the warning(s). MATLAB returns the current state of those warnings selected by the message identifier.

If you want to change state, but also save the former state so that you can restore it later, use the return structure array to save that state. The following example does an implicit query, returning state information in s, and then turns on all warnings.

See the section, Saving and Restoring State, for more information on restoring the former state of warnings.

Output Structure Array

Each element of the structure array returned by warning contains two fields.

Field Name
Message identifier string, 'all', or 'last'
State of warning(s) prior to invoking this control statement

If you query for the state of just one warning, using a message identifier or 'last' in the command, then MATLAB returns a one-element structure array. The identifier field contains the selected message identifier and the state field holds the current state of that warning:

If you query for the state of all warnings, using 'all' in the command, MATLAB returns a structure array having one or more elements:

Previous page  Warning Control Statements Saving and Restoring State Next page

© 1994-2005 The MathWorks, Inc.