23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8 Error Handling<br />

Warnings<br />

Like error, thewarning function alerts the user of unexpected conditions<br />

detected when running a program. However, warning does not halt the<br />

execution of the program. It displays the specified warning message and<br />

then continues.<br />

This section covers<br />

• “Reporting a Warning” on page 8-14<br />

• “Identifying the Cause” on page 8-15<br />

Reporting a Warning<br />

Use warning in your code to generate a warning message during execution.<br />

Specify the message string as the input argument to warning. For example,<br />

warning('Input must be a string')<br />

Warnings also differ from errors in that you can disable any warnings that<br />

you don’t want to see. You do this by invoking warning with certain control<br />

parameters. See “Warning Control” on page 8-16 for more information.<br />

Formatted Message Strings<br />

The warning message string that you specify can also contain formatting<br />

conversion characters, such as those used with the <strong>MATLAB</strong> sprintf<br />

function. Make the warning string the first argument, and then add any<br />

variables used by the conversion as subsequent arguments.<br />

warning('formatted_warningmsg', arg1, arg2, ...)<br />

For example, if your program cannot process a given parameter, you might<br />

report a warning with<br />

warning('Ambiguous parameter name, "%s".', param)<br />

<strong>MATLAB</strong> converts special characters (like \n and %d) in the warning message<br />

string only when you specify more than one input argument with warning.<br />

See “Formatted String Conversion” on page 8-5 for information.<br />

8-14

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

Saved successfully!

Ooh no, something went wrong!