Parse function inputs
The inputParser
object allows you to manage
inputs to a function by creating an input scheme. To check the input,
you can define validation functions for required arguments, optional
arguments, and name-value pair arguments. Optionally, you can set
properties to adjust the parsing behavior, such as handling case sensitivity,
structure array inputs, and inputs that are not in the input scheme.
After calling the parse
method to parse the
inputs, the inputParser
saves names and values
of inputs that match the input scheme (stored in Results
),
names of inputs that are not passed to the function and, therefore,
are assigned default values (stored in UsingDefaults
),
and names and values of inputs that do not match the input scheme
(stored in Unmatched
).
creates p
= inputParserinputParser
object p
.
|
Scalar logical value that indicates whether to match case when checking argument names. Possible values:
Default: | |||||
|
Character vector that specifies the name of the function to
include in error messages. By specifying the Default: The default value is an empty character vector, | |||||
|
Scalar logical value that indicates how to handle parameter name and value inputs that are not in the input scheme. Possible values:
Default: | |||||
|
Scalar logical value that indicates whether partial matching
of parameter names will be accepted. Partial parameter matching is
supported by the Possible values:
Default: | |||||
|
Scalar logical value that specifies whether to interpret a structure array as a single input or as a set of parameter name and value pairs.
Default: |
|
Cell array of character vectors that contains the names of arguments currently defined in the input scheme. Each method that adds an input argument to the scheme ( |
|
Structure containing names and values of inputs that match the
function input scheme, populated by the Each field of the |
|
Structure array containing the names and values of inputs that
do not match the function input scheme, populated by the If |
|
Cell array of character vectors containing the names of inputs
not passed explicitly to the function and assigned default values,
populated by the |
addOptional | Add optional positional argument to input parser scheme |
addParameter | Add optional parameter name-value pair argument to input parser scheme |
addParamValue | (Not recommended) Add parameter name and value argument to Input Parser scheme |
addRequired | Add required positional argument to input parser scheme |
parse | Parse function inputs |
You can define your scheme by calling addRequired
, addOptional
,
and addParameter
in any order, but when you call
your function that uses the input parser, you should pass in required
inputs first, followed by any optional positional inputs, and, finally,
any name-value pairs.
Handle. To learn how handle classes affect copy operations, see Copying Objects in the MATLAB documentation.
The copy
method creates another scheme with
the same properties as an existing inputParser
object:
pNew = copy(pOld);