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

numel — Return the number of outer array elements.

numel computes an exact checked product of visible dimensions and includes a compatibility-gated RunMat extension for selected dimensions.

Syntax

n = numel(A)
n = numel(A, dim1, dim2, ...)

Inputs

A
Type
Any
Required
Yes
Description
Value whose outer array elements are counted.
dim
Type
SizeArg
Required
Variadic
Description
RunMat-only positive integer dimension selectors.
NameTypeRequiredDefaultDescription
AAnyYes—Value whose outer array elements are counted.
dimSizeArgVariadic—RunMat-only positive integer dimension selectors.

Returns

n
Type
NumericScalar
Description
Exact element count as a host double scalar.
NameTypeDescription
nNumericScalarExact element count as a host double scalar.

Errors

RunMat:numel:InvalidDimensionType
When
A selector is not a numeric scalar or vector.
Message
numel: dimension selectors must be numeric scalars or one numeric vector
RunMat:numel:InvalidDimensionVector
When
The single vector selector is not vector-shaped.
Message
numel: dimension selector must be a vector
RunMat:numel:InvalidDimensionList
When
A vector occurs within a variadic scalar selector list.
Message
numel: separate dimension arguments must be scalars
IdentifierWhenMessage
RunMat:numel:InvalidDimensionTypeA selector is not a numeric scalar or vector.numel: dimension selectors must be numeric scalars or one numeric vector
RunMat:numel:InvalidDimensionVectorThe single vector selector is not vector-shaped.numel: dimension selector must be a vector
RunMat:numel:InvalidDimensionListA vector occurs within a variadic scalar selector list.numel: separate dimension arguments must be scalars
RunMat:numel:EmptyDimensionListNo selected dimensions remain after parsing.numel: dimension list must contain at least one element
RunMat:numel:NonFiniteDimensionA floating selector is not finite.numel: dimension must be finite
RunMat:numel:NonIntegerDimensionA floating selector is fractional.numel: dimension must be an integer
RunMat:numel:NonPositiveDimensionA selector is less than one.numel: dimension must be at least one
RunMat:numel:DimensionOutOfRangeA selector is outside the unsigned structural range.numel: dimension is outside the supported structural range
RunMat:numel:ResultNotExactDoubleThe product over dimensions overflows or is not exactly representable as double.numel: result exceeds exact double range
RunMat:numel:InternalErrorShape metadata is invalid.numel: invalid shape metadata
RunMat:numel:TooManyOutputsMore than one output is requested.numel: too many output arguments

Element count

numel(A) returns the product of the MATLAB-visible dimensions of A as a host double scalar. It counts outer array elements: cells rather than their contents, table rows times variables, string elements rather than characters within each string, and every character in a character array.

Any zero extent makes the result zero. Checked structural arithmetic detects an overflow before a result is formed, and RunMat rejects a count that the documented double result cannot represent exactly.

Selected-dimension extension

In RunMat compatibility mode, numel(A, dim1, dim2, ...) returns the checked product of selected extents. One dimension vector is also accepted. All eight integer classes are decoded exactly, dimensions beyond the visible rank contribute 1, and an empty selector is rejected.

The selected-dimension forms are a named RunMat extension. A MATLAB compatibility policy accepts only numel(A), matching the public compatible syntax.

Resident and distributed values

gpuArray and distributed inputs are counted from validated shape metadata. numel launches no kernel, calls no acceleration provider, transfers no payload, and returns one host scalar at a fusion boundary.

Examples

Count matrix elements

A = [1 2 3; 4 5 6];
n = numel(A)

Expected output:

n = 6

Count an N-D array

A = zeros(4, 4, 2);
n = numel(A)

Expected output:

n = 32

Count cells without inspecting their contents

C = {1, 2, 3; 4, 5, 6};
n = numel(C)

Expected output:

n = 6

Count characters in a character row

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

Expected output:

n = 6

Count an empty array

A = zeros(0, 7);
n = numel(A)

Expected output:

n = 0

Multiply selected dimensions

A = zeros(4, 3, 2);
n = numel(A, 1, 2)

Expected output:

n = 12

Count a resident array without gathering

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

Expected output:

n = 1024

Using numel with coding agents

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

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

FAQ

How is numel different from length?⌄

numel multiplies every dimension; length returns only the largest dimension.

When should I use size instead?⌄

Use size when individual extents or the complete shape are needed.

What does numel count in a cell array or struct array?⌄

It counts outer cells or struct elements and does not recurse into their contents or fields.

How are strings and character arrays different?⌄

A string scalar is one string-array element. A character row has one element per character.

What happens for an empty array?⌄

The product is zero when any visible extent is zero.

Are selected dimensions compatible syntax?⌄

No. They are enabled only by RunMat compatibility mode; the compatible public form is numel(A).

Does numel gather gpuArray or distributed data?⌄

No. Complete shape metadata is part of each validated handle.

Related Array functions

Introspection

height · iscolumn · isempty · ismatrix · isrow · isscalar · isvector · length · ndims · 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 numel is executed, line by line, in Rust.

  • View the source for numel 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
  • Element count
  • Selected-dimension extension
  • Resident and distributed values
  • Examples
  • Count matrix elements
  • Count an N-D array
  • Count cells without inspecting their contents
  • Count characters in a character row
  • Count an empty array
  • Multiply selected dimensions
  • Count a resident array without gathering
  • Using numel with coding agents
  • FAQ
  • Related Array functions
  • Introspection
  • Accumulation
  • Sorting Sets
  • Shape
  • Creation
  • Combinatorics
  • Binning
  • Indexing
  • Grouping
  • Source you can read
  • About RunMat