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
    • binocdf
    • boxplot
    • cdf
    • cdfplot
    • chi2cdf
    • corr
    • corrcoef
    • corrcov
    • cov
    • cov2corr
    • dummyvar
    • ecdf
    • filloutliers
    • fitdist
    • geomean
    • grpstats
    • harmmean
    • icdf
    • isoutlier
    • kstest
    • kurtosis
    • lsline
    • mad
    • mode
    • nanmax
    • normalize
    • normcdf
    • norminv
    • normpdf
    • onehotdecode
    • onehotencode
    • pdf
    • prctile
    • quantile
    • refline
    • rmse
    • skewness
    • tabulate
    • tcdf
    • tiedrank
    • tinv
    • tpdf
    • ttest2
    • wblinv

nanmax — Return maximum values while omitting NaNs.

nanmax is a compatibility form for maximum reductions and pairwise comparisons that ignore NaN values. It maps to max with "omitnan" semantics.

Syntax

M = nanmax(A)
[M, I] = nanmax(A)
M = nanmax(A, B)
M = nanmax(A, [], dim)
[M, I] = nanmax(A, [], dim)
M = nanmax(A, [], vecdim)
All supported nanmax forms
M = nanmax(A)
[M, I] = nanmax(A)
M = nanmax(A, B)
M = nanmax(A, [], dim)
[M, I] = nanmax(A, [], dim)
M = nanmax(A, [], vecdim)
[M, I] = nanmax(A, [], vecdim)
M = nanmax(A, [], "all")
[M, I] = nanmax(A, [], "all")
M = nanmax(A, [], "linear")
[M, I] = nanmax(A, [], "linear")
M = nanmax(A, [], "ComparisonMethod", method)
[M, I] = nanmax(A, [], "ComparisonMethod", method)
M = nanmax(A, B, "ComparisonMethod", method)

Inputs

NameTypeRequiredDefaultDescription
AAnyYes—Input scalar or array.
BAnyYes—Second operand for element-wise maximum.
placeholderAnyNo[]Empty placeholder selecting reduction-argument grammar.
dimAnyNo[]Reduction dimension selector (scalar or dimension vector).
flagStringScalarNo"all"Reduction mode flag: "all" or "linear".
optionNameStringScalarNo"ComparisonMethod"Option name (currently "ComparisonMethod").
methodStringScalarNo"auto"Comparison method: "auto", "abs"/"magnitude", or "real".

Returns

NameTypeDescription
MNumericArrayMaximum values.
INumericArrayOne-based maximum indices/origins.

Returned values from nanmax depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:max:InvalidArgumentArgument grammar, dimensions, or option names/values are invalid.max: invalid argument
RunMat:max:InvalidInputInput values cannot be converted to supported max domains.max: invalid input
RunMat:max:SizeMismatchElement-wise operands are not broadcast-compatible.max: size mismatch
RunMat:max:InternalExecution fails due to gather, provider, allocation, or conversion internals.max: internal failure

How nanmax works

  • nanmax(X) reduces along the first non-singleton dimension and skips NaN values in each slice.
  • nanmax(X, [], dim) and nanmax(X, [], vecdim) reduce along the specified dimension or dimension vector.
  • nanmax(X, [], 'all') collapses every element into a scalar; nanmax(X, [], 'linear') also returns linear indices when two outputs are requested.
  • nanmax(..., 'ComparisonMethod', method) supports the same real and complex comparison modes as max while still omitting NaNs.
  • nanmax(A, B) performs elementwise maximum with MATLAB implicit expansion and chooses the non-NaN side when exactly one operand is NaN.
  • If every value considered for a result is NaN, the returned value is NaN.
  • Two-output calls return one-based indices or origins using the same conventions as max.

GPU memory and residency

nanmax gathers GPU inputs to host memory when omit-NaN semantics are required, then returns the MATLAB-compatible host result.

Examples

Column-wise maxima ignoring NaNs

A = [NaN 4 2; 3 NaN NaN];
M = nanmax(A)

Expected output:

M = [3 4 2]

Pairwise maximum ignoring NaNs

P = nanmax([NaN 2 NaN], [3 NaN NaN])

Expected output:

P = [3 2 NaN]

Using nanmax with coding agents

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

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

FAQ

Should new code use nanmax or max(..., 'omitnan')?⌄

Use max(..., 'omitnan') for new MATLAB-style code. nanmax is provided for compatibility with existing codebases.

Does nanmax support pairwise array inputs?⌄

Yes. nanmax(A, B) uses the same implicit expansion and origin-index behavior as max(A, B), while omitting NaNs.

Related Stats functions

Summary

binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv

Ml

bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · squareform · test · training · tsne

Random

binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd

Hist

histc · histcounts · histcounts2

Options

statget · statset

Open-source implementation

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

  • View the source for nanmax 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 nanmax works
  • GPU memory and residency
  • Examples
  • Column-wise maxima ignoring NaNs
  • Pairwise maximum ignoring NaNs
  • Using nanmax with coding agents
  • FAQ
  • Related Stats functions
  • Summary
  • Ml
  • Random
  • Hist
  • Options
  • Open-source implementation
  • About RunMat