This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: inputParser

(Not recommended) Add parameter name and value argument to Input Parser scheme

addParamValue is not recommended. Use addParameter instead.




addParamValue(p,paramName,default) adds parameter name and value argument paramName to the input scheme of inputParser object p. When the inputs that you are checking do not include a value for this optional parameter, the parser assigns the default value.

addParamValue(p,paramName,default,validationFcn) specifies a validation function for the input argument.

Input Arguments


Object of class inputParser.


String scalar or character vector that specifies the internal name for the input parameter.

Parameter names and values are optional inputs. When calling the function, name and value pairs can appear in any order, with the general form Name1,Value1,...,NameN,ValueN.


Default value for the input. This value can be of any data type.


Handle to a function that checks if the input argument is valid.

inputParser accepts two types of validation functions: functions that return true or false, and functions that pass or throw an error. Both types of validation functions must accept a single input argument.


expand all

Create an inputParser object and add an optional input named myparam with a default value of 0 to the input scheme.

p = inputParser;
paramName = 'myparam';
default = 0;

Unlike the positional inputs added with the addRequired and addOptional methods, each parameter added with addParameter corresponds to two input arguments: one for the name and one for the value of the parameter.

Pass both the parameter name and value to the parse method.

ans = struct with fields:
    myparam: 100

Check whether the value corresponding to myparam is a numeric scalar greater than zero.

p = inputParser;
paramName = 'myparam';
default = 1;
validationFcn = @(x) isnumeric(x) && isscalar(x) && (x > 0);

The syntax @(x) creates a handle to an anonymous function with one input.

Attempt to parse an invalid value, such as -1:

Argument 'myparam' failed validation @(x)isnumeric(x)&&isscalar(x)&&(x>0).


  • If your parameter values do not require validation, you do not have to include them in the input scheme with addParamValue. As an alternative, set the KeepUnmatched property of the inputParser object to true. The parser stores extra parameter names and values in the Unmatched property rather than in the Results property of the object. For an example, see the inputParser reference page.

Introduced in R2007a

Was this topic helpful?