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.

8 Error Handling<br />

You must type the command using the <strong>MATLAB</strong> function format; that is,<br />

parentheses and quotation marks are required.<br />

Note <strong>MATLAB</strong> does not display warning output if you do not assign the<br />

output to a variable.<br />

This example turns off divideByZero warnings for the <strong>MATLAB</strong> component,<br />

and returns the identifier and previous state in a 1-by-1 structure array.<br />

s = warning('off','<strong>MATLAB</strong>:divideByZero')<br />

s =<br />

identifier: '<strong>MATLAB</strong>:divideByZero'<br />

state: 'on'<br />

You can use output variables with any type of warning control statement. If<br />

you just want to collect the information but don’t want to change state, then<br />

simply perform a query on the warning(s). <strong>MATLAB</strong> returns the current state<br />

of those warnings selected by the message identifier.<br />

s = warning('query', 'msg_id');<br />

Ifyouwanttochangestate,butalsosave the former state so that you can<br />

restoreitlater,usethereturnstructurearraytosavethatstate.Thefollowing<br />

example does an implicit query, returning state information in s, andthen<br />

turns on all warnings.<br />

s = warning('on', 'all');<br />

See the section, “Saving and Restoring State” on page 8-22, for more<br />

information on restoring the former state of warnings.<br />

Output Structure Array<br />

Each element of the structure array returned by warning contains two fields.<br />

8-20

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

Saved successfully!

Ooh no, something went wrong!