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 than minArgs or greater than maxArgs. If the number of inputs is between minArgs and maxArgs (inclusive), then narginchk does nothing.
To verify that you have a minimum number of arguments, but no maximum number, set maxArgs to inf. 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 and maxArgs. 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 and maxArgs is nargin(fun), then you do not need to use narginchk.