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.

Function Arguments<br />

Save the M-file, and then run it as shown here:<br />

publish_ip('ipscript.m', 'ppt', 'outputDir', ...<br />

'C:/matlab/test', 'maxWidth', 500, 'maxHeight', 300);<br />

The output is<br />

The input parameters for this program are:<br />

format<br />

maxHeight<br />

maxWidth<br />

outputDir<br />

script<br />

Parsing Parameter Values on the Function Call<br />

Once you have constructed a schema that represents all possible inputs<br />

to the function, the next task is to write the code that parses and verifies<br />

these arguments whenever the function is called. The parse method of the<br />

inputParser class reads and validates the required script argument and<br />

any optional arguments that follow it in the argument list:<br />

p.parse(script, varargin{:});<br />

Execution of the parse method validates each argument and also builds a<br />

structure from the input arguments. The name of the structure is Results,<br />

which is accessible as a property of the object. To get the value of all<br />

arguments, type<br />

p.Results<br />

To get the value of any single input argument, type<br />

p.Results.argname<br />

where argname is the name of the argument. Continue with the publish_ip<br />

exercise started earlier in this section by removing the sprintf statement<br />

that was inserted in the last section, and then adding the following lines:<br />

% Parse and validate all input arguments.<br />

p.parse(script, varargin{:});<br />

4-41

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

Saved successfully!

Ooh no, something went wrong!