Input parser for functions
The inputParser
object enables you to manage inputs to a function by creating an input parser 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 parser scheme.
After defining your input parser scheme, call the parse
function. The inputParser
stores information about inputs.
Input Names and Values | Where Stored |
---|---|
Matching input parser scheme | Results property |
Not passed to function and, therefore, assigned default values | UsingDefaults property |
No matching input parser scheme | Unmatched property |
creates an input parser object with default property values.p
= inputParser
addOptional | Add optional, positional argument into input parser scheme |
addParameter | Add optional name-value pair argument into input parser scheme |
addRequired | Add required, positional argument into input parser scheme |
parse | Parse function inputs |
addParamValue | (Not recommended) Add optional name-value pair argument into input parser scheme |
You can define your input parser scheme by calling the addRequired
, addOptional
, and addParameter
functions in any order. However, when you call the function that uses the input parser, arguments are passed in this order:
Required arguments
Any optional, positional arguments
Any name-value pairs
Arguments added to the input parser scheme with the addOptional
function are positional. Therefore, add them to the input parser scheme in the same order they are passed into the function.
Use addOptional
to add an individual argument into the input parser scheme. If you want to parse an optional name-value pair, then use the addParameter
function.