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.

4 M-File <strong>Programming</strong><br />

This section covers the following topics<br />

• “Defining a Specification for Each Input Parameter” on page 4-38<br />

• “Parsing Parameter Values on the Function Call” on page 4-41<br />

• “Packaging Arguments in a Structure” on page 4-42<br />

• “Arguments That Default” on page 4-44<br />

• “Validating the Input Arguments” on page 4-44<br />

• “Making a Copy of the Schema” on page 4-47<br />

• “Summary of inputParser Methods” on page 4-47<br />

• “Summary of inputParser Properties that Control Parsing” on page 4-47<br />

• “Summary of inputParser Properties that Provide Information” on page<br />

4-48<br />

To illustrate how to use the inputParser class, the documentation in this<br />

section develops a new M-file program called publish_ip, (based on the<br />

<strong>MATLAB</strong> publish function). There are three calling syntaxes for this<br />

function:<br />

publish_ip('script')<br />

publish_ip('script', 'format')<br />

publish_ip('script', options)<br />

There is one required argument (script), one optional argument (format),<br />

and a number of optional arguments that are specified as parameter-value<br />

pairs (options).<br />

Defining a Specification for Each Input Parameter<br />

Most programs have a block of code toward the beginning that parses the<br />

values in the input argument list and checks these values against what is<br />

expected. The inputParser classprovidesthefollowingmethodswithwhich<br />

you can specify what the inputs are and whether they are required, optional,<br />

or to be specified using the parameter-value syntax:<br />

• addRequired — Add a required parameter to the schema<br />

• addOptional — Add an optional parameter to the schema<br />

4-38

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

Saved successfully!

Ooh no, something went wrong!