narginchk — Validate the number of inputs supplied to the current function.
narginchk(minArgs,maxArgs) throws when the current function received fewer than minArgs or more than maxArgs inputs.
Syntax
narginchk(minArgs, maxArgs)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
minArgs | NumericScalar | Yes | — | Minimum allowed argument count. |
maxArgs | NumericScalar | Yes | — | Maximum allowed argument count. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:NotEnoughInputs | The current function was called with fewer inputs than the lower bound. | narginchk: not enough input arguments |
RunMat:TooManyInputs | The current function was called with more inputs than the upper bound. | narginchk: too many input arguments |
RunMat:NarginchkArgumentInvalid | A bound argument is not a nonnegative integer scalar or valid Inf upper bound. | narginchk: bounds must be nonnegative integer scalars |
RunMat:NarginchkBoundsInvalid | The minimum bound is greater than the maximum bound. | narginchk: minArgs must be less than or equal to maxArgs |
RunMat:NarginchkContextUnavailable | The runtime dispatcher is invoked without VM function-call context. | narginchk: function call context is unavailable |
How narginchk works
minArgsaccepts nonnegative scalar single, double, or any of the eight integer classes.maxArgsaccepts the same classes and also positive double infinity for an unbounded maximum.- All integer classes are read from authoritative scalar storage without floating conversion.
- The minimum cannot exceed the maximum, and bounds outside the host argument-count range are rejected rather than rounded or saturated.
- The check uses the current VM function-call context and has no output value.
Example
Require one or two inputs
function y = f(x, varargin)
narginchk(1, 2);
y = x;
endExpected output:
Calls with one or two inputs continue; other calls throw.Using narginchk with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how narginchk changes the result.
Run a small narginchk example, explain the result, then change one input and compare the output.
Related Introspection functions
addprop · assignin · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · evalc · feval · findprop · getcallinfo · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · keyboard · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mislocked · mlock · munlock · namelengthmax · nargoutchk · notify · onCleanup · stats · str2func · superclasses · underlyingType · verLessThan · version · which · who · whos
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how narginchk is executed, line by line, in Rust.
- View the source for narginchk in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.