nargoutchk — Validate requested function outputs or return a legacy output-count message.
nargoutchk(minArgs,maxArgs) throws when the current function's requested output count is outside the bounds. The discouraged three- and four-input forms validate an explicit count and return a message instead of throwing for a count violation.
Syntax
nargoutchk(minArgs, maxArgs)
msgText = nargoutchk(minArgs, maxArgs, numArgs)
msgStruct = nargoutchk(minArgs, maxArgs, numArgs, 'struct')Inputs
minArgs- Type
NumericScalar- Required
- Yes
- Description
- Minimum allowed argument count.
maxArgs- Type
NumericScalar- Required
- Yes
- Description
- Maximum allowed argument count.
numArgs- Type
NumericScalar- Required
- Yes
- Description
- Legacy explicit output count to validate.
outputType- Type
StringScalar- Required
- Yes
- Default
struct- Description
- Literal struct output selector.
Returns
msg- Type
Any- Description
- Legacy message text or structure.
Errors
RunMat:NotEnoughOutputs- When
- The current function was called with fewer requested outputs than the lower bound.
- Message
nargoutchk: not enough output arguments
RunMat:TooManyOutputs- When
- The current function exceeds maxArgs or the caller requests more results than the selected form returns.
- Message
nargoutchk: too many output arguments
RunMat:NargoutchkArgumentInvalid- When
- A bound argument is not a nonnegative integer scalar or valid Inf upper bound.
- Message
nargoutchk: bounds must be nonnegative integer scalars
Forms and results
The two-input form uses the selected function invocation's requested output count and produces no output; requesting a result reports RunMat:TooManyOutputs. A script or context-free embedding has no function output count and reports RunMat:NargoutchkContextUnavailable after its bounds are admitted.
msg = nargoutchk(minArgs,maxArgs,numArgs) returns character message text on a violation and an empty 0-by-0 character array otherwise. With a fourth 'struct' selector it returns a structure with message and identifier fields on a violation and an empty structure otherwise. These legacy forms return at most one result; a discarded call produces no result.
minArgs, maxArgs, and legacy numArgs accept scalar single, double, or any of the eight integer classes. Positive single or double infinity is allowed only for maxArgs. Exact integer storage is compared without floating conversion; out-of-range counts reject rather than round or saturate.
Interactive resident controls are not documented and reject before provider access. These forms are host-only and perform no provider operation or callback.
Examples
Require one requested function output
y = arity_output_probe(7);Inspect an explicit output-count violation
msg = nargoutchk(1,1,0); detail = nargoutchk(1,1,0,'struct');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
addlistener · addParameter · addprop · assignin · builtin · cancel · class · clear · clearAllMemoizedCaches · clearCache · clearvars · dbclear · dbstack · dbstatus · dbtype · eval · evalc · evalin · feval · findprop · func2str · functions · get.p · getcallinfo · getmethod · inputname · inputParser · isa · ischar · isdeployed · iskeyword · ismethod · isobject · isstring · isUnderlyingType · isvalid · keyboard · loadobj · localfunctions · matlab.metadata.DynamicProperty.delete · memoize · metaclass · mfilename · mislocked · mlock · munlock · namelengthmax · narginchk · new_object · notify · numArgumentsFromSubscript · onCleanup · parse · saveobj · set.p · stats · str2func · subsasgn · subsref · superclasses · underlyingType · verLessThan · version · which · who · whos
Source you can read
Every RunMat function's source is public. 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 a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.