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

Enabling Case-Sensitive Matching. When you pass optional arguments<br />

in the function call, <strong>MATLAB</strong> compares these arguments with the names of<br />

parameter-value argument names in the schema. By default, <strong>MATLAB</strong> does<br />

not use case sensitivity in this comparison. So, an argument name entered<br />

into the schema (using addParamValue) asmaxHeight will match an argument<br />

passed as MAXHeight in the function call. You can override the default and<br />

make these comparisons case sensitive by setting the CaseSensitive property<br />

of the object to true. <strong>MATLAB</strong> does not error on a case mismatch, however,<br />

unless the KeepUnmatched property is set to false: its default state.<br />

At some point in your publish_ip M-file before executing the parse method,<br />

set KeepUnmatched to false and CaseSensitive to true, and then execute<br />

the publish_ip function using MAXHeight asthenameoftheargumentfor<br />

specifying maximum height:<br />

p.KeepUnmatched = false;<br />

p.CaseSensitive = true;<br />

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

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

Save and run the function, using MAXHeight asthenameoftheargumentfor<br />

specifying maximum height:<br />

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

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

??? Argument 'MAXHeight' did not match any valid parameter of<br />

the parser.<br />

Error in ==> publish_ip at 17<br />

AddingtheFunctionNametoErrorMessages. Use the FunctionName<br />

property to include the name of your function in error messages thrown by<br />

the validating function:<br />

At some point in your publish_ip M-file before executing the parse method,<br />

set the FunctionName property to PUBLISH_IP, and then run the function:<br />

p.FunctionName = 'PUBLISH_IP';<br />

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

4-46

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

Saved successfully!

Ooh no, something went wrong!