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

nan — Create arrays filled with IEEE NaN values using MATLAB-compatible size, class, and like forms.

nan(...) creates NaN-filled arrays across scalar, vector, matrix, and N-D size signatures, with MATLAB-compatible class and 'like' option behavior.

Syntax

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

Inputs

NameTypeRequiredDefaultDescription
nSizeArgYes—Square size.
size_vectorSizeArgYes—Size vector defining output dimensions.
dimsSizeArgVariadic—Dimension sizes.
typenameStringScalarNo"double"Class name override (double|single|gpuArray).
like_kwStringScalarYes"like"Like keyword.
prototypeLikePrototypeYes—Prototype array used for class/device.

Returns

NameTypeDescription
ANumericArrayNaN-filled output array.

Errors

IdentifierWhenMessage
—The 'like' keyword is provided without a prototype argument.nan: expected prototype after 'like'
—A class keyword and a 'like' prototype are both provided.nan: cannot combine 'like' with other class specifiers
—A trailing option string is not a supported class keyword.nan: unrecognised option
—The 'like' keyword is specified more than once.nan: multiple 'like' specifications are not supported
—The 'like' prototype has an integer data type that cannot represent NaN.nan: integer 'like' prototypes are not supported

How nan works

  • nan() returns the scalar NaN.
  • nan(n) returns an n x n double array filled with NaN.
  • nan(m, n, ...) returns a dense double array with the requested dimensions.
  • nan(sz) accepts a size vector and returns an array with prod(sz) NaN elements.
  • nan(A) returns a NaN array with the same size as A.
  • nan(___, 'single') returns a single-precision numeric array.
  • nan(___, 'like', prototype) matches numeric precision and device residency for supported prototype arrays.

Does RunMat run nan on the GPU?

Provider-backed nan construction uses constant-fill hooks, so fully resident GPU pipelines can create NaN arrays without first materializing a host tensor when provider support is available.

GPU memory and residency

When a GPU prototype is supplied, RunMat preserves residency by allocating the output through the active acceleration provider. If the provider cannot fill on device, RunMat falls back to a host NaN tensor and uploads it.

Examples

Creating a 2x3 matrix of NaN values

A = nan(2, 3)

Expected output:

A = [NaN NaN NaN; NaN NaN NaN]

Creating a single-precision NaN array

A = nan(4, 1, 'single')

Expected output:

A = [NaN; NaN; NaN; NaN]

Creating a GPU-resident NaN array like a prototype

G = gpuArray(rand(2,2));
A = nan(2, 2, 'like', G)

Expected output:

A = [NaN NaN; NaN NaN]

Using nan with coding agents

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

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

FAQ

How is nan different from NaN?⌄

Both bare identifiers resolve to the scalar IEEE NaN constant. The callable form nan(...) constructs NaN-filled arrays.

Does nan(n) create a row vector?⌄

No. MATLAB compatibility requires nan(n) to create an n x n matrix. Use nan(1, n) or nan(n, 1) for vectors.

Can nan create GPU arrays?⌄

Yes. With a GPU prototype, nan(..., 'like', G) asks the active acceleration provider to allocate a NaN-filled GPU tensor.

Related Array functions

Creation

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

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

Indexing

find · ind2sub · sub2ind

Introspection

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

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how nan is executed, line by line, in Rust.

  • View the source for nan 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 nan works
  • Does RunMat run nan on the GPU?
  • GPU memory and residency
  • Examples
  • Creating a 2x3 matrix of NaN values
  • Creating a single-precision NaN array
  • Creating a GPU-resident NaN array like a prototype
  • Using nan with coding agents
  • FAQ
  • Related Array functions
  • Creation
  • Grouping
  • Sorting Sets
  • Shape
  • Indexing
  • Introspection
  • Open-source implementation
  • About RunMat