mustBeInRange — Validate that numeric values fall within lower and upper bounds, including inclusive/exclusive interval options.
mustBeInRange is available as a callable MATLAB argument validator. It returns no user-facing value when validation passes and throws a structured RunMat error when validation fails. Validators with literal/static payloads are also encoded in MATLAB arguments blocks; dynamic validator payload expressions should call the validator directly until runtime-evaluated arguments-block payloads are implemented.
Syntax
mustBe*(A, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
A | Any | Yes | — | Value to validate. |
B | Any | Variadic | — | Additional validator-specific argument. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:validators:ValidationFailed | A value does not satisfy the requested validator. | argument validation failed |
RunMat:validators:InvalidArgument | A validator receives an unsupported argument count or argument type. | invalid argument validation input |
How mustBeInRange works
- Callable validator forms enforce exact supported arity, throw on validation failure, and suppress automatic output on success.
- Arguments-block validation uses the same shared runtime predicates for validators that RunMat can encode statically.
- Numeric validators check every element without materializing a cloned numeric array, including sparse stored values and implicit sparse zeros where relevant.
- Text validators accept string scalars/arrays, character row vectors, and compatible cell arrays of text where MATLAB commonly permits them.
mustBeInRangesupports default inclusive bounds, a single"inclusive"or"exclusive"flag, two per-bound"inclusive"/"exclusive"flags, and compatibility aliases for excluding one bound.
Example
Using the validator as a normal callable guard
mustBeInRange(A, 0, 1, "exclusive")Expected output:
No output when validation passes; an error is thrown when validation fails.Using mustBeInRange with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how mustBeInRange changes the result.
Run a small mustBeInRange example, explain the result, then change one input and compare the output.
FAQ
Does this validator work in an arguments block?⌄
Yes for literal/static validator payloads that RunMat can encode at compile time. Dynamic validator payload expressions should use the callable form for now.
Related Argument Validation functions
isvarname · mustBeA · mustBeColumn · mustBeFile · mustBeFinite · mustBeFloat · mustBeFolder · mustBeGreaterThan · mustBeGreaterThanOrEqual · mustBeInteger · mustBeLessThan · mustBeLessThanOrEqual · mustBeMember · mustBeNegative · mustBeNonempty · mustBeNonmissing · mustBeNonNan · mustBeNonnegative · mustBeNonpositive · mustBeNonsparse · mustBeNonzero · mustBeNonzeroLengthText · mustBeNumeric · mustBeNumericOrLogical · mustBePositive · mustBeReal · mustBeScalarOrEmpty · mustBeSparse · mustBeText · mustBeTextScalar · mustBeUnderlyingType · mustBeValidVariableName · mustBeVector · namedargs2cell · validateFunctionSignaturesJSON
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.