| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
p.createCopy
createCopy(p)
p.createCopy creates a copy of inputParser object p. Because the inputParser class uses handle semantics, a normal assignment statement does not create a copy.
createCopy(p) is functionally the same as the syntax above.
For more information on the inputParser class, see Validating Inputs with inputParser in the MATLAB Programming Fundamentals documentation.
Write an M-file function called publish_ip, based on the MATLAB publish function, to illustrate the use of the inputParser class. Construct an instance of inputParser and assign it to variable p:
function publish_ip(script, varargin) p = inputParser; % Create an instance of the inputParser class.
Add arguments to the schema. See the reference pages for the addRequired, addOptional, and addParamValue methods for help with this:
p.addRequired('script', @ischar);
p.addOptional('format', 'html', ...
@(x)any(strcmpi(x,{'html','ppt','xml','latex'})));
p.addParamValue('outputDir', pwd, @ischar);
p.addParamValue('maxHeight', [], @(x)x>0 && mod(x,1)==0);
p.addParamValue('maxWidth', [], @(x)x>0 && mod(x,1)==0);
Make a copy of object p, assigning it to variable x. Use the Parameters property of inputParser to list the arguments belonging to each object:
disp(' ')
disp 'The input parameters for object p are'
disp(p.Parameters')
x = p.createCopy;
disp(' ')
disp 'The input parameters for the copy of object p are'
disp(x.Parameters')Save the M-file using the Save option on the MATLAB File menu, and then run it:
publish_ip('ipscript.m', 'ppt', 'maxWidth', 500, 'MAXHeight', 300);
The input parameters for object p are
'format'
'maxHeight'
'maxWidth'
'outputDir'
'script'
The input parameters for the copy of object p are
'format'
'maxHeight'
'maxWidth'
'outputDir'
'script'
inputParser, addRequired(inputParser), addOptional(inputParser), addParamValue(inputParser), parse(inputParser)
![]() | createClassFromWsdl | createSoapMessage | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |