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.1, Nov 17, 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
    • height
    • iscolumn
    • isempty
    • ismatrix
    • isrow
    • isscalar
    • isvector
    • length
    • ndims
    • numel
    • size
    • width

length — Return the largest dimension of an array.

length reads MATLAB-visible shape metadata and returns the largest extent as an exact host double scalar.

Syntax

n = length(A)

Inputs

A
Type
Any
Required
Yes
Description
Value whose MATLAB-visible dimensions are inspected.
NameTypeRequiredDefaultDescription
AAnyYes—Value whose MATLAB-visible dimensions are inspected.

Returns

n
Type
NumericScalar
Description
Exact largest visible dimension extent of the input.
NameTypeDescription
nNumericScalarExact largest visible dimension extent of the input.

Errors

RunMat:length:UnsupportedTable
When
The input is a table or timetable.
Message
length: tables and timetables are not supported; use height, width, or size
RunMat:length:ResultNotExactDouble
When
The largest dimension cannot be represented exactly by the documented double output.
Message
length: result exceeds exact double range
RunMat:length:InternalError
When
Value or distributed shape metadata is invalid.
Message
length: invalid shape metadata
RunMat:length:TooManyOutputs
When
More than one output is requested.
Message
length: too many output arguments
IdentifierWhenMessage
RunMat:length:UnsupportedTableThe input is a table or timetable.length: tables and timetables are not supported; use height, width, or size
RunMat:length:ResultNotExactDoubleThe largest dimension cannot be represented exactly by the documented double output.length: result exceeds exact double range
RunMat:length:InternalErrorValue or distributed shape metadata is invalid.length: invalid shape metadata
RunMat:length:TooManyOutputsMore than one output is requested.length: too many output arguments

Largest dimension

length(A) returns the largest extent in the MATLAB-visible shape of A as a double scalar. Scalars have length 1; row and column vectors return their populated dimension; matrices and N-D arrays return the largest extent across all dimensions.

For empty arrays, zero extents participate like any other dimension. zeros(0, 0) has length 0, while zeros(0, 7) and zeros(0, 0, 5) have lengths 7 and 5.

Containers and text

Character, string, cell, struct, object, sparse, complex, and logical arrays use their outer array dimensions. A string scalar such as "abc" has length 1; use strlength to count characters in string elements.

A containers.Map handle reports its entry count. Tables and timetables are rejected because their conventional dimensions have dedicated height, width, and size queries.

Resident and distributed values

gpuArray and distributed inputs are classified from validated shape metadata. length does not launch a kernel, call an acceleration provider, or transfer payload data. The result is a host double scalar and forms a fusion boundary.

RunMat returns an error if a distributed extent is too large to be represented exactly by the documented double result instead of silently rounding the structural value.

Examples

Measure a row vector

row = [1 2 3 4];
n = length(row)

Expected output:

n = 4

Find the longer matrix dimension

A = randn(5, 12);
n = length(A)

Expected output:

n = 12

Inspect an empty rectangular array

E = zeros(0, 7);
n = length(E)

Expected output:

n = 7

Measure a character row

name = 'RunMat';
n = length(name)

Expected output:

n = 6

Distinguish string shape from text length

n = length("RunMat")

Expected output:

n = 1

Inspect every dimension of an N-D array

A = zeros(2, 9, 4);
n = length(A)

Expected output:

n = 9

Inspect a resident shape

G = gpuArray(ones(256, 4));
n = length(G)

Expected output:

n = 256

Using length with coding agents

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

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

FAQ

How is length different from size?⌄

length(A) returns only the largest dimension as a scalar. size(A) exposes individual dimensions or the complete dimension vector.

What does length return for a scalar?⌄

A scalar has visible shape 1-by-1, so the result is 1.

How are empty arrays handled?⌄

The largest extent is returned. zeros(0, 0) has length 0, while zeros(0, 5) has length 5.

Does length gather gpuArray data?⌄

No. The resident handle carries the complete shape metadata needed by the query.

Can length inspect cells, structs, and objects?⌄

Yes. Their outer MATLAB-visible array dimensions determine the result; contents do not.

Does length count characters or encoded bytes?⌄

It reports character-array dimensions. For string scalars it reports the 1-by-1 container shape; use strlength to count text.

Why are tables rejected?⌄

Use height, width, or size to state which tabular dimension the program needs.

Can length appear beside fused GPU work?⌄

Yes. It reads metadata and returns a host scalar at a fusion boundary without moving the input payload.

Related Array functions

Introspection

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

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

Indexing

find · ind2sub · sub2ind

Grouping

findgroups · groupcounts · grp2idx · splitapply

Source you can read

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

  • View the source for length 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
  • Largest dimension
  • Containers and text
  • Resident and distributed values
  • Examples
  • Measure a row vector
  • Find the longer matrix dimension
  • Inspect an empty rectangular array
  • Measure a character row
  • Distinguish string shape from text length
  • Inspect every dimension of an N-D array
  • Inspect a resident shape
  • Using length with coding agents
  • FAQ
  • Related Array functions
  • Introspection
  • Accumulation
  • Sorting Sets
  • Shape
  • Creation
  • Combinatorics
  • Binning
  • Indexing
  • Grouping
  • Source you can read
  • About RunMat