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 />

% Display the value of a specific argument.<br />

disp(' ')<br />

disp(sprintf('\nThe maximum height is %d.', p.Results.maxHeight))<br />

% Display all arguments.<br />

disp(' ')<br />

disp 'List of all arguments:'<br />

disp(p.Results)<br />

Now save and execute the M-file, passing the required script argument, the<br />

optional format argument, as well as several parameter-value arguments.<br />

<strong>MATLAB</strong> assigns those values you pass in the argument list to the<br />

appropriate fields of the Results structure:<br />

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

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

The maximum height is 300.<br />

List of all arguments:<br />

format: 'ppt'<br />

maxHeight: 300<br />

maxWidth: 500<br />

outputDir: 'C:/matlab/test'<br />

script: 'ipscript.m'<br />

Packaging Arguments in a Structure<br />

By setting the StructExpand property of the inputParser object to true, you<br />

can pass arguments to your function in the form of a structure instead of<br />

individually in the argument list. This property must be set prior to calling<br />

the parse method.<br />

StructExpand defaults to the true state, so you don’t have to make any<br />

changes to your test program to run this example.<br />

Put all of the input arguments into a structure:<br />

s.format = 'xml';<br />

s.outputDir = 'C:/matlab/test';<br />

4-42

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

Saved successfully!

Ooh no, something went wrong!