narginchk
Validate number of input arguments
Description
narginchk(
validates the number of input arguments in the call to the currently executing function. minArgs
,maxArgs
)narginchk
throws an error if the number of inputs specified in the call is fewer than minArgs
or greater than maxArgs
. If the number of inputs is between minArgs
and maxArgs
(inclusive), then narginchk
does nothing.
Examples
Input Arguments
Tips
To verify that you have a minimum number of arguments, but no maximum number, set
maxArgs
toinf
. For example:narginchk(5,inf)
throws an error when there are fewer than five inputs.To verify that you have an exact number of arguments, specify the same value for
minArgs
andmaxArgs
. For example:narginchk(3,3)
throws an error if you do not have exactly three inputs.If you call a function with too few inputs, the message identifier and message are:
identifier: 'MATLAB:narginchk:notEnoughInputs' message: 'Not enough input arguments.'
When too many inputs are supplied, the message identifier and message are:
identifier: 'MATLAB:narginchk:tooManyInputs' message: 'Too many input arguments.'
If
minArgs
is 0 andmaxArgs
isnargin(fun)
, then you do not need to usenarginchk
.
Extended Capabilities
Version History
Introduced in R2011b