Programming |
Saving and Restoring State
If you want to temporarily change the state of some warnings and then later return to your original settings, you can save the original state in a structure array and then restore it from that array. You can save and restore the state of all of your warnings or just one that you select with a message identifier.
To save the current warning state, assign the output of a warning control statement, as discussed in the last section, Output from Control Statements. The following statement saves the current state of all warnings in structure array s
.
To restore state from s
, use the syntax shown below. Note that the MATLAB function format (enclosing arguments in parentheses) is required.
Example 1 -- Performing an Explicit Query
Perform a query of all warnings to save the current state in structure array s
.
Then, after doing some work that includes making changes to the state of some warnings, restore the original state of all warnings.
Example 2 -- Performing an Implicit Query
Turn on one particular warning, saving the previous state of this warning in s
. Remember that this nonquery syntax (where state
equals on
or off
) performs an implicit query prior to setting the new state.
Restore the state of that one warning when you are ready, with
Output from Control Statements | Debug, Backtrace, and Verbose Modes |
© 1994-2005 The MathWorks, Inc.