Validate number of input arguments
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 thanminArgs
or greater thanmaxArgs
. If the number of inputs is betweenminArgs
andmaxArgs
(inclusive), thennarginchk
does nothing.
To verify that you have a minimum number of arguments, but no maximum number, setmaxArgs
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 forminArgs
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:
标识符:“MATLAB: narginchk:notEnoughInputs' message: 'Not enough input arguments.'
When too many inputs are supplied, the message identifier and message are:
标识符:“MATLAB: narginchk:tooManyInputs' message: 'Too many input arguments.'
IfminArgs
is 0 andmaxArgs
isnargin(fun)
, then you do not need to usenarginchk
.