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
    • find
    • ind2sub
    • sub2ind

ind2sub — Convert one-based linear indices to N-D subscripts.

ind2sub converts column-major linear indices using a positive integral size vector. Requested output count controls trailing-dimension collapse; an internal call with no requested-output context uses a cell carrier.

Syntax

[I1,...,IN] = ind2sub(sz, ind)

Inputs

sz
Type
SizeArg
Required
Yes
Description
Size vector describing source array dimensions.
ind
Type
Any
Required
Yes
Description
Linear indices to convert into per-dimension subscripts.
NameTypeRequiredDefaultDescription
szSizeArgYes—Size vector describing source array dimensions.
indAnyYes—Linear indices to convert into per-dimension subscripts.

Returns

I1,...,IN
Type
NumericArray
Description
Requested double subscript arrays; the final requested output folds trailing dimensions.
NameTypeDescription
I1,...,INNumericArrayRequested double subscript arrays; the final requested output folds trailing dimensions.

Returned values from ind2sub depend on how many outputs the caller requests.

Errors

RunMat:ind2sub:InvalidInput
When
Size vector or linear index inputs are malformed or unsupported.
Message
ind2sub: invalid input arguments
RunMat:ind2sub:ProviderError
When
Provider-side ind2sub execution fails or returns malformed outputs.
Message
ind2sub: provider execution failed
RunMat:ind2sub:InternalError
When
Internal tensor/materialization logic fails while building outputs.
Message
ind2sub: internal error
IdentifierWhenMessage
RunMat:ind2sub:InvalidInputSize vector or linear index inputs are malformed or unsupported.ind2sub: invalid input arguments
RunMat:ind2sub:ProviderErrorProvider-side ind2sub execution fails or returns malformed outputs.ind2sub: provider execution failed
RunMat:ind2sub:InternalErrorInternal tensor/materialization logic fails while building outputs.ind2sub: internal error

Dimensions and requested outputs

The size vector contains at least two positive integral extents. Each requested output is a double subscript array. Fewer requested outputs fold trailing dimensions into the final output; with one output this is the original linear index. Extra outputs extend singleton dimensions.

Each output array follows the input index shape, including empty and N-D forms. Positive indices beyond the nominal product extend the final effective dimension, subject to exact structural bounds. An internal callable without a requested-output count retains a cell carrier for all per-dimension outputs.

Numeric and resident behavior

Size extents and indices accept single, double, and all eight native integer classes; wide integers are decoded exactly. Subscripts are doubles. Complex, fractional, nonfinite, and nonpositive values reject.

The binary64 WGPU route can execute admitted forms on device. Other providers use exact owner-aware materialization and restoration where binary64 output is representable. No fusion occurs.

Examples

Compile requested subscripts and errors

sz = [3 4]; indices = [7 8 9]; [row,col] = ind2sub(sz,indices); linear = ind2sub(sz,indices); invalid = [2 0]; caught = false; try; bad = ind2sub(invalid,1); catch failure; caught = strcmp(failure.identifier,'RunMat:ind2sub:InvalidInput'); end

Reject a zero dimension

I = ind2sub([2 0], 1)

Recover row and column

[row,col] = ind2sub([3 4], 8)

Expected output:

row = 2, col = 3

Convert several indices

[row,col] = ind2sub([3 5], [7 8 9])

Expected output:

row = [1 2 3], col = [3 3 3]

Collapse dimensions into one output

I = ind2sub([3 4], [1 8])

Expected output:

I = [1 8]

Using ind2sub with coding agents

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

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

FAQ

What happens with fewer outputs?⌄

Trailing dimensions collapse into the final requested subscript.

Do output shapes match the input indices?⌄

Yes, including empty arrays and N-D index arrays.

Related Array functions

Indexing

find · sub2ind

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

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 · range · sparse · spdiags · speye · spones · sprand · true · uint16.empty · uint32.empty · uint64.empty · uint8.empty · zeros

Combinatorics

combinations · nchoosek · perms

Binning

discretize

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 ind2sub is executed, line by line, in Rust.

  • View the source for ind2sub 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
  • Dimensions and requested outputs
  • Numeric and resident behavior
  • Examples
  • Compile requested subscripts and errors
  • Reject a zero dimension
  • Recover row and column
  • Convert several indices
  • Collapse dimensions into one output
  • Using ind2sub with coding agents
  • FAQ
  • Related Array functions
  • Indexing
  • Accumulation
  • Sorting Sets
  • Shape
  • Creation
  • Combinatorics
  • Binning
  • Grouping
  • Introspection
  • Source you can read
  • About RunMat