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

squareform — Convert between condensed distance vectors and square symmetric matrices.

squareform converts a condensed pairwise-distance vector into a square symmetric matrix, or converts a square symmetric distance matrix back into condensed form.

Syntax

Y = squareform(Z)
Y = squareform(Z, Force)

Inputs

Z
Type
Any
Required
Yes
Description
Condensed distance vector or square distance matrix.
force
Type
StringScalar
Required
No
Description
Conversion direction: 'tomatrix' or 'tovector'.
NameTypeRequiredDefaultDescription
ZAnyYes—Condensed distance vector or square distance matrix.
forceStringScalarNo—Conversion direction: 'tomatrix' or 'tovector'.

Returns

Y
Type
Any
Description
Square symmetric matrix or condensed distance vector, preserving the input class.
NameTypeDescription
YAnySquare symmetric matrix or condensed distance vector, preserving the input class.

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

Behavior

Vector inputs must have length n*(n-1)/2 for an integer n. Condensed vectors use the same pair ordering as pdist.

Matrix inputs must be square and symmetric with a zero diagonal. Floating-point symmetry and zero tests use RunMat's distance tolerance; integer and logical comparisons remain exact.

squareform(Z,"tomatrix") forces vector-to-matrix conversion; squareform(Z,"tovector") forces matrix-to-vector conversion. Without a direction, vectors expand and nonvector matrices condense.

The conversion preserves single, double, and logical classes. RunMat mode also preserves all eight typed-integer classes as an extension. Structural integer values do not pass through double.

Execution

Automatically resident inputs may gather to host for structural conversion. An explicit gpuArray input is a RunMat-only extension. squareform has no GPU kernel or fused path.

The entire output must fit host memory. Shape and option errors are checked before output construction.

Examples

Expand a condensed vector

D = [5 4 7]; M = squareform(D)

Expected output:

M = [0 5 4; 5 0 7; 4 7 0]

Convert back to condensed form

M = [0 5 4; 5 0 7; 4 7 0]; D2 = squareform(M)

Expected output:

D2 = [5 4 7]

Force vector-to-matrix conversion

D = [5 4 7]; M = squareform(D,"tomatrix")

Expected output:

M is the 3-by-3 symmetric distance matrix.

Preserve logical distance storage

D = logical([1 0 1]); M = squareform(D); V = squareform(M)

Expected output:

Both M and V have logical class; V equals D.

Using squareform with coding agents

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

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

FAQ

Why does a matrix input need a zero diagonal?⌄

A distance matrix represents distance from each observation to itself on the diagonal, which must be zero for condensed conversion.

Related Stats functions

Ml

bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · nlparci · optimizableVariable · pdist · pdist2 · perfcurve · predict · regress · ridge · 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
  • Behavior
  • Execution
  • Examples
  • Expand a condensed vector
  • Convert back to condensed form
  • Force vector-to-matrix conversion
  • Preserve logical distance storage
  • Using squareform with coding agents
  • FAQ
  • Related Stats functions
  • Ml
  • Summary
  • Random
  • Hist
  • Options
  • About RunMat