nargoutchk — Validate requested function outputs or create a legacy output-count message.
nargoutchk(minArgs,maxArgs) throws when the current function's requested output count is outside the bounds. The discouraged legacy forms return message text or a message structure for an explicit numArgs count.
Syntax
nargoutchk(minArgs, maxArgs)
msgText = nargoutchk(minArgs, maxArgs, numArgs)
msgStruct = nargoutchk(minArgs, maxArgs, numArgs, 'struct')Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
minArgs | NumericScalar | Yes | — | Minimum allowed argument count. |
maxArgs | NumericScalar | Yes | — | Maximum allowed argument count. |
numArgs | NumericScalar | Yes | — | Legacy explicit output count to validate. |
outputType | StringScalar | Yes | struct | Literal struct output selector. |
Returns
| Name | Type | Description |
|---|---|---|
msg | Any | Legacy message text or structure. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:NotEnoughOutputs | The current function was called with fewer requested outputs than the lower bound. | nargoutchk: not enough output arguments |
RunMat:TooManyOutputs | The current function was called with more requested outputs than the upper bound. | nargoutchk: too many output arguments |
RunMat:NargoutchkArgumentInvalid | A bound argument is not a nonnegative integer scalar or valid Inf upper bound. | nargoutchk: bounds must be nonnegative integer scalars |
RunMat:NargoutchkBoundsInvalid | The minimum bound is greater than the maximum bound. | nargoutchk: minArgs must be less than or equal to maxArgs |
RunMat:NargoutchkContextUnavailable | The runtime dispatcher is invoked without VM function-call context. | nargoutchk: function call context is unavailable |
How nargoutchk works
minArgs,maxArgs, and legacynumArgsaccept scalar single, double, or any of the eight integer classes; positive double infinity is allowed only asmaxArgs.- All integer classes are read from authoritative scalar storage without floating conversion.
- The two-argument form uses the current VM output-call context and throws on a violation.
msg = nargoutchk(minArgs,maxArgs,numArgs)returns character message text on a violation and an empty0×0character array otherwise.msg = nargoutchk(minArgs,maxArgs,numArgs,'struct')returns a structure withmessageandidentifierfields on a violation and an empty structure otherwise.- Bounds outside the host argument-count range are rejected rather than rounded or saturated.
Example
Require exactly one requested output
function y = f(x)
nargoutchk(1, 1);
y = x;
endExpected output:
Calls requesting exactly one output continue; other calls throw.Using nargoutchk with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how nargoutchk changes the result.
Run a small nargoutchk 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 · narginchk · 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 nargoutchk is executed, line by line, in Rust.
- View the source for nargoutchk 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.