RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

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.

LicensePrivacy
/
See all docs
Builtin Reference
    • iscolumn
    • isempty
    • ismatrix
    • isrow
    • isscalar
    • isvector
    • length
    • ndims
    • numel
    • size

length — Return largest-dimension length in MATLAB and RunMat.

length(A) returns the size of the largest dimension of A. Scalar/vector/matrix conventions and N-D behavior follow MATLAB semantics.

Syntax

n = length(A)

Inputs

NameTypeRequiredDefaultDescription
AAnyYes—Input value to inspect.

Returns

NameTypeDescription
nNumericScalarLargest dimension extent of input.

Errors

IdentifierWhenMessage
RunMat:length:UnsupportedTableThe input is a table or timetable.length: tables and timetables are not supported; use height, width, or size

How length works

  • The result is always a double-precision scalar.
  • Empty arrays report 0 when every dimension is zero; otherwise the maximum non-zero dimension is reported (e.g., 0×5 arrays have length 5).
  • Character arrays and string arrays follow their array dimensions, not the number of code points.
  • Cell arrays use their MATLAB array shape (rows × cols) with the maximum dimension returned.
  • GPU-resident arrays are inspected entirely through shape metadata already carried by the tensor handle; length never gathers the payload.
  • Tables and timetables are rejected; use height, width, or size for tabular values.
  • Arguments that are not arrays (scalars, logicals, strings, handle objects) are treated as 1×1.

Does RunMat run length on the GPU?

length is a metadata-only query. For a resident tensor, RunMat reads GpuTensorHandle.shape directly and returns a host double scalar. It does not consult the provider, gather or download the payload, launch a kernel, or allocate a device buffer.

Examples

Determine the length of a row vector

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

Expected output:

n = 4

Find the longer side of a rectangular matrix

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

Expected output:

len = 12

Handle empty arrays that still have a non-zero dimension

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

Expected output:

len = 7

Measure the length of a character array

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

Expected output:

len = 6

Inspect the length of a gpuArray without gathering

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

Expected output:

len = 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 the maximum dimension length as a scalar, whereas size(A) returns every dimension in a row vector. Use length when you only care about the longest dimension.

What does length return for scalars?⌄

Scalars are treated as 1×1, so length(scalar) returns 1.

How does length behave for empty arrays?⌄

If all dimensions are zero, length returns 0. If any dimension is non-zero, the maximum dimension is returned. For example, zeros(0, 5) has length 5, but zeros(0, 0) has length 0.

Does length gather GPU data?⌄

No. The runtime reads shape metadata stored in the GPU tensor handle and never accesses the provider or downloads the tensor payload.

Can I use length on cell arrays and structs?⌄

Yes. length examines the MATLAB array shape of the container, so cell arrays and struct arrays return the maximum dimension of their array layout.

Does length count characters or bytes?⌄

For character arrays, the length reflects the array dimensions (rows and columns), not encoded byte length or Unicode scalar counts.

What about string arrays?⌄

String arrays are treated like any other array. String scalars are 1×1, so length("abc") returns 1. Use strlength if you need the number of characters in each element.

Is length safe to use inside fused GPU expressions?⌄

Yes. length never allocates or keeps data on the GPU. It returns a host scalar immediately, so it won't break fusion plans.

Related Array functions

Introspection

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

Grouping

accumarray · combinations · discretize · findgroups · groupcounts · grp2idx · splitapply

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 · squeeze · toeplitz · tril · triu · vertcat

Creation

colon · createArray · empty · eye · false · full · inf · linspace · logspace · magic · meshgrid · nan · nchoosek · ndgrid · nonzeros · ones · peaks · perms · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · zeros

Indexing

find · ind2sub · sub2ind

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. 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 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.

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
  • How length works
  • Does RunMat run length on the GPU?
  • Examples
  • Determine the length of a row vector
  • Find the longer side of a rectangular matrix
  • Handle empty arrays that still have a non-zero dimension
  • Measure the length of a character array
  • Inspect the length of a gpuArray without gathering
  • Using length with coding agents
  • FAQ
  • Related Array functions
  • Introspection
  • Grouping
  • Sorting Sets
  • Shape
  • Creation
  • Indexing
  • Open-source implementation
  • About RunMat