RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.2, Nov 26, 2026 ·

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • colon
    • createArray
    • empty
    • eye
    • false
    • full
    • inf
    • int16.empty
    • int32.empty
    • int64.empty
    • int8.empty
    • linspace
    • logspace
    • magic
    • meshgrid
    • nan
    • ndgrid
    • nonzeros
    • ones
    • peaks
    • rand
    • randi
    • randn
    • randperm
    • range
    • sparse
    • spdiags
    • speye
    • spones
    • sprand
    • true
    • uint16.empty
    • uint32.empty
    • uint64.empty
    • uint8.empty
    • zeros

range — Compute the span of array data as max - min, with MATLAB-compatible dimension and NaN controls.

range(X) returns the span (maximum minus minimum) of the elements in X. For arrays, it operates along the first non-singleton dimension unless you specify dim or 'all', and it follows MATLAB-compatible output-shape conventions.

Syntax

y = range(X)
y = range(X, dim)
y = range(X, vecdim)
y = range(X, "all")
y = range(X, nanflag)
y = range(X, dim_or_vecdim, nanflag)

Inputs

X
Type
NumericArray
Required
Yes
Description
Input data.
dim
Type
IntegerScalar
Required
No
Description
Reduction dimension.
vecdim
Type
SizeArg
Required
No
Description
Vector of reduction dimensions.
all_kw
Type
StringScalar
Required
No
Default
"all"
Description
Reduce over all elements.
nanflag
Type
StringScalar
Required
No
Default
"includenan"
Description
NaN handling flag ('omitnan'|'includenan').
dim_or_vecdim
Type
SizeArg
Required
No
Description
Dimension selector.
NameTypeRequiredDefaultDescription
XNumericArrayYes—Input data.
dimIntegerScalarNo—Reduction dimension.
vecdimSizeArgNo—Vector of reduction dimensions.
all_kwStringScalarNo"all"Reduce over all elements.
nanflagStringScalarNo"includenan"NaN handling flag ('omitnan'|'includenan').
dim_or_vecdimSizeArgNo—Dimension selector.

Returns

y
Type
NumericArray
Description
Range result (max-min).
NameTypeDescription
yNumericArrayRange result (max-min).

Errors

—
When
'all' is combined with an explicit dimension.
Message
range: 'all' cannot be combined with an explicit dimension
—
When
More than one explicit dimension selector is provided.
Message
range: too many dimension arguments
—
When
Dimension arguments are non-integer, non-finite, or < 1.
Message
range: dimension must be >= 1
IdentifierWhenMessage
—'all' is combined with an explicit dimension.range: 'all' cannot be combined with an explicit dimension
—More than one explicit dimension selector is provided.range: too many dimension arguments
—Dimension arguments are non-integer, non-finite, or < 1.range: dimension must be >= 1
—Dimension selector is GPU-resident.range: dimension arguments must reside on the host (numeric or string)
—Dimension selector has unsupported value type or shape.range: unsupported dimension argument type

Behavior

Operates on scalars, vectors, matrices, and N-D tensors.

range(X) measures the spread along the first non-singleton dimension.

range(X, dim) targets a specific dimension.

range(X, vecdim) reduces across multiple dimensions at once.

range(X, 'all') collapses all elements to a single scalar result.

range(___) is equivalent to max(___) - min(___) over the requested slice.

vecdim accepts a row or column vector of positive integers; duplicate entries are ignored.

range(___, 'omitnan') ignores NaN values (resulting in NaN if a slice has no finite values).

range(___, 'includenan') (default) returns NaN for any slice containing NaN.

Works with gpuArray inputs; the runtime keeps residency on the GPU when provider hooks are available.

Execution and residency

You generally do not need to call gpuArray explicitly in RunMat. When the input is already on the GPU, the planner keeps the result on-device if the active provider exposes reduce_min, reduce_max, the corresponding *_dim reductions, and elementwise subtraction. Current providers specialise 2-D reductions; multi-axis reductions, tensors with more than two dimensions, or 'omitnan' requests gather back to the host for correctness. When a required hook is missing, RunMat gathers the data automatically, computes on the CPU, and returns a standard tensor.

Uses provider min/max reductions when available; falls back to the host when omitnan is requested or when multi-dimension reductions are unsupported.

Examples

Measuring column-wise range of a matrix

A = [1 4 2; 3 7 5];
spread = range(A)

Expected output:

% Each column's maximum minus minimum
spread = [2 3 3]

Selecting a dimension explicitly

A = [1 4 2; 3 7 5];
row_spread = range(A, 2)

Expected output:

row_spread = [3; 4]

Collapsing all elements with 'all'

temperatures = [68 72 75; 70 74 78];
overall = range(temperatures, 'all')

Expected output:

overall = 10

Ignoring NaNs when computing range

samples = [2 NaN 5; 4 6 NaN];
spread = range(samples, 1, 'omitnan')

Expected output:

spread = [2 0 0]

Keeping gpuArray results on the device

G = gpuArray([1 10 3; 2 8 4]);
column_spread = range(G);
gather(column_spread)

Expected output:

ans =
     1     2     1

Handling higher-dimensional inputs

data = reshape(1:24, [3, 4, 2]);
slice_spread = range(data, [1 2])

Expected output:

slice_spread(:,:,1) =
    11

slice_spread(:,:,2) =
    11

Using range with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how range changes the result.

Run a small range example, explain the result, then change one input and compare the output.

FAQ

What does range(X) return for scalars?⌄

The range of a scalar is always 0, because the maximum and minimum coincide.

How are NaN values treated by default?⌄

By default ('includenan'), any slice containing NaN yields NaN. Use 'omitnan' to ignore them.

Can I supply multiple dimensions?⌄

Yes. Pass a vector such as [1 3] to reduce across both the first and third dimensions simultaneously.

What happens if I request a dimension larger than ndims(X)?⌄

RunMat mirrors MATLAB: a size-1 dimension produces zeros (or NaN when the lone value is NaN).

Does range support integer and logical inputs?⌄

Yes. The inputs are promoted to double precision internally, matching MATLAB semantics.

How does range interact with gpuArray?⌄

The runtime asks the active provider for min/max reductions. When unavailable, it gathers the data and computes on the CPU.

Why is the output sometimes a scalar and sometimes a vector?⌄

The output collapses the selected dimensions to size 1, leaving other dimensions unchanged. A single remaining element becomes a scalar.

How can I inspect the range across all elements quickly?⌄

Use range(X, 'all') to flatten all dimensions into a single scalar spread.

Related Array functions

Creation

colon · createArray · empty · eye · false · full · inf · int16.empty · int32.empty · int64.empty · int8.empty · linspace · logspace · magic · meshgrid · nan · ndgrid · nonzeros · ones · peaks · rand · randi · randn · randperm · sparse · spdiags · speye · spones · sprand · true · uint16.empty · uint32.empty · uint64.empty · uint8.empty · zeros

Accumulation

accumarray

Sorting Sets

argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique

Shape

blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · shiftdim · squeeze · toeplitz · tril · triu · vertcat

Combinatorics

combinations · nchoosek · perms

Binning

discretize

Indexing

find · ind2sub · sub2ind

Grouping

findgroups · groupcounts · grp2idx · splitapply

Introspection

height · iscolumn · isempty · ismatrix · isrow · isscalar · isvector · length · ndims · numel · size · width

Source you can read

Every RunMat function's source is public. Read exactly how range is executed, line by line, in Rust.

  • View the source for range 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.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Behavior
  • Execution and residency
  • Examples
  • Measuring column-wise range of a matrix
  • Selecting a dimension explicitly
  • Collapsing all elements with 'all'
  • Ignoring NaNs when computing range
  • Keeping gpuArray results on the device
  • Handling higher-dimensional inputs
  • Using range with coding agents
  • FAQ
  • Related Array functions
  • Creation
  • Accumulation
  • Sorting Sets
  • Shape
  • Combinatorics
  • Binning
  • Indexing
  • Grouping
  • Introspection
  • Source you can read
  • About RunMat