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
    • 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

zeros — Create zero-filled arrays with a selected shape, class, storage, and residency.

zeros creates scalar, matrix, or N-D zero values from dimensions or a size vector. Numeric class names and like prototypes select typed storage and supported placement. For an object prototype, zeros(..., 'like', prototype) invokes its zerosLike(prototype, ...) method, or its static zeros(...) method if zerosLike is absent. Dimension arguments retain their original order and form. Method errors are returned without trying another creation method.

Syntax

A = zeros()
A = zeros(n)
A = zeros(size_vector)
A = zeros(m, n, ...)
A = zeros(prototype)
A = zeros(..., typename)
A = zeros(..., "like", prototype)

Inputs

n
Type
SizeArg
Required
Yes
Description
Square size.
size_vector
Type
SizeArg
Required
Yes
Description
Size vector defining output dimensions.
dims
Type
SizeArg
Required
Variadic
Description
Dimension sizes.
prototype
Type
LikePrototype
Required
Yes
Description
Prototype value when no numeric dimension arguments are provided.
typename
Type
StringScalar
Required
No
Default
"double"
Description
Class name override.
like_kw
Type
StringScalar
Required
Yes
Default
"like"
Description
Like keyword.
prototype
Type
LikePrototype
Required
Yes
Description
Prototype array used for class/device.
NameTypeRequiredDefaultDescription
nSizeArgYes—Square size.
size_vectorSizeArgYes—Size vector defining output dimensions.
dimsSizeArgVariadic—Dimension sizes.
prototypeLikePrototypeYes—Prototype value when no numeric dimension arguments are provided.
typenameStringScalarNo"double"Class name override.
like_kwStringScalarYes"like"Like keyword.
prototypeLikePrototypeYes—Prototype array used for class/device.

Returns

A
Type
NumericArray
Description
Output array.
A
Type
Any
Description
Numeric output selected by the prototype, or the object creation method's result.
NameTypeDescription
ANumericArrayOutput array.
AAnyNumeric output selected by the prototype, or the object creation method's result.

Errors

—
When
The 'like' keyword is provided without a prototype argument.
Message
zeros: expected prototype after 'like'
—
When
A class keyword and a 'like' prototype are both provided.
Message
zeros: cannot combine 'like' with other class specifiers
—
When
A trailing option string is not a supported class keyword.
Message
zeros: unrecognised option
—
When
The 'like' keyword is specified more than once.
Message
zeros: multiple 'like' specifications are not supported
IdentifierWhenMessage
—The 'like' keyword is provided without a prototype argument.zeros: expected prototype after 'like'
—A class keyword and a 'like' prototype are both provided.zeros: cannot combine 'like' with other class specifiers
—A trailing option string is not a supported class keyword.zeros: unrecognised option
—The 'like' keyword is specified more than once.zeros: multiple 'like' specifications are not supported

Behavior

zeros() returns scalar double zero. zeros(n) creates an n-by-n matrix; separate dimensions or a row size vector create the requested dense N-D shape. Size controls accept double, single, and all eight fixed-width integer classes.

A trailing class name selects double, single, logical, or any fixed-width integer output. zeros(..., "like", prototype) preserves the prototype's class, sparsity, complexity, and supported residency. Integer output uses native fixed-width storage.

RunMat mode additionally accepts a column size vector, a resident numeric size control, or a prototype without the like keyword. Use the explicit compatible forms when source must run under a MATLAB compatibility pin.

GPU execution

A resident like prototype selects its owning provider and physical element type. RunMat asks that provider for a zero-filled allocation and can fall back to a typed host upload when the provider lacks a zero-allocation hook.

The planner may also place eligible constructor results on an accelerator when doing so benefits a surrounding expression. Explicit resident prototypes retain user-selected placement and ownership.

Examples

Create scalar zero

z = zeros()

Expected output:

z = 0

Create a rectangular matrix

A = zeros(2, 3)

Expected output:

A = [0 0 0; 0 0 0]

Create a logical column

mask = zeros(4, 1, "logical")

Expected output:

mask is a 4-by-1 logical array of false values

Create native fixed-width integer storage

counts = zeros(2, 3, "uint16")

Expected output:

counts is a 2-by-3 uint16 matrix

Create an N-D array from a size vector

T = zeros([2 3 4]);
shape = size(T)

Expected output:

shape = [2 3 4]

Match a host prototype's class

prototype = single([1 2; 3 4]);
A = zeros(3, 2, "like", prototype)

Expected output:

A is a 3-by-2 single matrix

Allocate zeros with a resident prototype

prototype = gpuArray(single([1 2; 3 4]));
G = zeros(3, 2, "like", prototype);
host = gather(G)

Expected output:

host is a 3-by-2 single matrix

Infer shape and class from a prototype in RunMat mode

prototype = int32([1 2; 3 4]);
A = zeros(prototype)

Expected output:

A is a 2-by-2 int32 zero matrix

Using zeros with coding agents

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

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

FAQ

What does zeros() return?⌄

It returns scalar double zero.

What does zeros(n) return?⌄

It returns an n-by-n dense double matrix.

How do I create an N-D array?⌄

Pass each dimension separately or provide one row size vector, such as zeros([2 3 4]).

Which output classes can I request?⌄

Double, single, logical, and all eight fixed-width integer classes are supported.

How do I match another value?⌄

Use zeros(..., "like", prototype) to preserve its class, sparsity, complexity, and supported residency.

Can zeros allocate on a GPU?⌄

Yes. A resident like prototype selects the owning provider; the planner can also place eligible results automatically.

Does a provider need a native zero-allocation hook?⌄

No. RunMat can upload a correctly typed host zero value when that hook is unavailable.

Is zeros(A) portable prototype syntax?⌄

No. The implicit prototype form is a RunMat extension; use zeros(..., "like", A) for compatible source.

Is output always dense?⌄

Ordinary constructor forms are dense. A sparse like prototype preserves sparse storage.

Why preallocate with zeros?⌄

Preallocation fixes the intended class and shape before indexed assignment and can avoid repeated growth.

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

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

  • View the source for zeros 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
  • GPU execution
  • Examples
  • Create scalar zero
  • Create a rectangular matrix
  • Create a logical column
  • Create native fixed-width integer storage
  • Create an N-D array from a size vector
  • Match a host prototype's class
  • Allocate zeros with a resident prototype
  • Infer shape and class from a prototype in RunMat mode
  • Using zeros with coding agents
  • FAQ
  • Related Array functions
  • Creation
  • Accumulation
  • Sorting Sets
  • Shape
  • Combinatorics
  • Binning
  • Indexing
  • Grouping
  • Introspection
  • Source you can read
  • About RunMat