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
    • bayesopt
    • classify
    • confusionmat
    • crossvalind
    • cvpartition
    • fitclinear
    • fitctree
    • fitlm
    • kmeans
    • knnsearch
    • lasso
    • lassoglm
    • linkage
    • lscov
    • mnrfit
    • nlparci
    • optimizableVariable
    • pdist
    • pdist2
    • perfcurve
    • predict
    • regress
    • ridge
    • squareform
    • test
    • training
    • tsne

pdist — Compute pairwise distances between rows of an observation matrix.

pdist(X) returns a condensed row vector containing distances between every pair of rows in X, ordered like the lower-left distance triangle: (2,1), (3,1), ..., (n,1), (3,2), ....

Syntax

D = pdist(X)
D = pdist(X, Distance, DistParameter)

Inputs

X
Type
NumericArray
Required
Yes
Description
Observation matrix with observations in rows.
options
Type
Any
Required
Variadic
Description
Distance metric, optional metric parameter, or CacheSize.
NameTypeRequiredDefaultDescription
XNumericArrayYes—Observation matrix with observations in rows.
optionsAnyVariadic—Distance metric, optional metric parameter, or CacheSize.

Returns

D
Type
NumericArray
Description
Pairwise distances in double precision.
NameTypeDescription
DNumericArrayPairwise distances in double precision.

Errors

RunMat:distance:InvalidArgument
When
Distance inputs, dimensions, metrics, or controls are malformed.
Message
distance helper: invalid argument
RunMat:distance:Internal
When
RunMat cannot allocate or construct a distance output.
Message
distance helper: internal error
IdentifierWhenMessage
RunMat:distance:InvalidArgumentDistance inputs, dimensions, metrics, or controls are malformed.distance helper: invalid argument
RunMat:distance:InternalRunMat cannot allocate or construct a distance output.distance helper: internal error

Observations and metrics

X must be a real numeric vector or two-dimensional matrix. Rows are observations and columns are variables. The default metric is Euclidean distance.

Supported named metrics are euclidean, squaredeuclidean, cityblock, chebychev, minkowski, seuclidean, mahalanobis, cosine, correlation, hamming, jaccard, and spearman. Custom distance functions are not supported.

pdist(X,"minkowski",P) uses a positive finite exponent. pdist(X,"seuclidean",S) uses a positive finite standard-deviation vector; without S, RunMat estimates column variances from X, omitting NaNs from scale estimation. pdist(X,"mahalanobis",C) accepts a covariance matrix; without C, RunMat computes and inverts covariance from X.

Classes and execution

Results are double row vectors. Typed-integer observation data, distance parameters, and CacheSize are independently gated RunMat extensions. They must be exactly representable at the binary64 distance boundary. CacheSize is validated for compatibility but does not change the present CPU algorithm.

Resident inputs are gathered through their owning provider and pairwise distances run on CPU. This is a materializing fusion boundary, not a GPU distance kernel.

Examples

Compute Euclidean distances

X = [0 0; 3 4; 4 0; 0 2]; D = pdist(X)

Expected output:

D starts with [5 4 2], the distances from rows 2, 3, and 4 to row 1.

Use a cityblock metric

X = [0 0; 3 4; 4 0; 0 2]; D = pdist(X,"cityblock")

Expected output:

D contains Manhattan distances between row pairs.

Use Minkowski distance

X = [0 0; 3 4; 4 0]; D = pdist(X,"minkowski",3)

Expected output:

D contains pairwise L3 distances.

Using pdist with coding agents

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

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

FAQ

Why is the output a row vector?⌄

Condensed form avoids duplicating a symmetric matrix. Use squareform to expand it.

Are custom distance functions supported?⌄

No. RunMat currently supports the named numeric distance metrics listed above.

Related Stats functions

Ml

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

Summary

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

Random

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

Hist

histc · histcounts · histcounts2

Options

statget · statset

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
  • Observations and metrics
  • Classes and execution
  • Examples
  • Compute Euclidean distances
  • Use a cityblock metric
  • Use Minkowski distance
  • Using pdist with coding agents
  • FAQ
  • Related Stats functions
  • Ml
  • Summary
  • Random
  • Hist
  • Options
  • About RunMat