FUNCTION REFERENCE

squareform

Convert between condensed distances and symmetric square form.

Convert between condensed distances and symmetric square form.

Syntax

Y = squareform(X,direction)

A distance vector becomes a symmetric matrix with zero diagonal; a square matrix becomes a row vector in pdist order. Optional direction is 'tomatrix' or 'tovector'. Scalar input defaults to 'tomatrix', including zero. Input matrices must be symmetric with exactly zero diagonal. Empty vectors represent a single observation.

Example

m = squareform([5 3 4]); v = squareform(m);   % v = [5 3 4]

Differences from MATLAB: Two-dimensional real numeric data only. Symmetry is checked exactly, with matching NaNs accepted.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.