msg = nargchk(minArgs, maxArgs, n)
msg = nargchk(minArgs, maxArgs, n, 'string')
msgstruct = nargchk(minArgs, maxArgs, n, 'struct')
| Parameter | Description |
|---|---|
| minArgs | minimum number of accepted inputs (scalar integer value). |
| maxArgs | maximum number of accepted inputs (scalar integer value). |
| n | number of supplied inputs to check, usually nargin (scalar integer value). |
| 'string' or 'struct' | output type: 'string' (default) returns a character message, 'struct' returns an error structure. |
| Parameter | Description |
|---|---|
| msg | a character row vector error message, or '' (empty) if n is in the range [minArgs, maxArgs]. |
| msgstruct | a structure with fields message and identifier (a 1x0 empty structure if n is in range). |
nargchk checks whether the number of input arguments n falls within the range [minArgs, maxArgs].
It returns the message 'Not enough input arguments.' when n is less than minArgs, 'Too many input arguments.' when n is greater than maxArgs, and an empty result otherwise.
It is typically used as error(nargchk(minArgs, maxArgs, nargin)) at the start of a function.
nargchk is deprecated and kept for compatibility with legacy code. Use narginchk instead in new code.
msg = nargchk(2, 3, 1)
msg = nargchk(1, 2, 3)
msg = nargchk(1, 3, 2)
| Version | Description |
|---|---|
| 2.0.0 | initial version |