nargchk
Validate the number of input arguments.
Syntax
Section titled “Syntax”msg = nargchk(nminarg, nmaxarg, numargs)msg = nargchk(nminarg, nmaxarg, numargs, 'string')Description
Section titled “Description”Returns an error message string if numargs is outside [nminarg, nmaxarg], otherwise returns an empty string. The 'string' flag controls return format. Used inside function bodies to validate argument count before processing.
Note: superseded by direct comparisons (if nargin < N || nargin > M) in modern code.
Examples
Section titled “Examples”function foo(a, b, c) msg = nargchk(2, 3, nargin); error(msg);endSee also
Section titled “See also”nargoutchk— Validate the number of output arguments.nargin— Number of input arguments passed to the current function.nargout— Number of output arguments requested by the caller.