disp(p.UsingDefaults)
end
Step 7. Call your function.
The Input Parser expects to receive inputs as follows:
• Required inputs first, in the order they are added to the parsing scheme with addRequired.
• Optional positional inputs in the order they are added to the scheme with addOptional.
• Positional inputs before parameter name and value pair inputs.
• Parameter names and values in the form Name1,Value1,...,NameN,ValueN.
Pass several combinations of inputs to printPhoto, some valid and some invalid:
printPhoto('myfile.jpg')
File name: myfile.jpg
Finish: glossy
Using defaults:
'finish'
'color'
'width'
'height'
printPhoto(100)
Error using printPhoto (line 23)
The value of 'filename' is invalid. It must satisfy the function: ischar.
printPhoto('myfile.jpg','satin')
Error using printPhoto (line 23)
The value of 'finish' is invalid. Expected input to match one of these strings:
'glossy', 'matte'
The input, 'satin', did not match any of the valid strings.
printPhoto('myfile.jpg',height=10,width=8)
File name: myfile.jpg
Finish: glossy
Using defaults:
'finish'
'color'
When using name-value arguments before R2021a, pass names as strings or character vectors, and
separate names and values with commas. For example:
printPhoto('myfile.jpg','height',10,'width',8)
To pass a value for the nth positional input, either specify values for the previous (n – 1) inputs or
pass the input as a parameter name and value pair. For example, these function calls assign the same
values to finish (default 'glossy') and color:
printPhoto('myfile.gif','glossy','CMYK') % positional
printPhoto('myfile.gif',color='CMYK')
% name and value
See Also
inputParser | varargin
Parse Function Inputs
21-15
Précédent

- 771/1450

Suivant