Statistics: pdist

### Function Reference: `pdist`

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

Return the distance between any two rows in X.

`D = pdist (X` calculates the euclidean distance between pairs of observations in X. X must be an M×P numeric matrix representing M points in P-dimensional space. This function computes the pairwise distances returned in D as an M×(M-1)/P row vector. Use `Z = squareform (D)` to convert the row vector D into a an M×M symmetric matrix Z, where `Z(i,j)` corresponds to the pairwise distance between points `i` and `j`.

`D = pdist (X, Y, Distance)` returns the distance between pairs of observations in X using the metric specified by Distance, which can be any of the following options.

`"euclidean"` |  | Euclidean distance.
`"squaredeuclidean"` |  | Squared Euclidean distance.
`"seuclidean"` |  | standardized Euclidean distance. Each coordinate difference between the rows in X and the query matrix Y is scaled by dividing by the corresponding element of the standard deviation computed from X. A different scaling vector can be specified with the subsequent DistParameter input argument.
`"mahalanobis"` |  | Mahalanobis distance, computed using a positive definite covariance matrix. A different covariance matrix can be specified with the subsequent DistParameter input argument.
`"cityblock"` |  | City block distance.
`"minkowski"` |  | Minkowski distance. The default exponent is 2. A different exponent can be specified with the subsequent DistParameter input argument.
`"chebychev"` |  | Chebychev distance (maximum coordinate difference).
`"cosine"` |  | One minus the cosine of the included angle between points (treated as vectors).
`"correlation"` |  | One minus the sample linear correlation between observations (treated as sequences of values).
`"hamming"` |  | Hamming distance, which is the percentage of coordinates that differ.
`"jaccard"` |  | One minus the Jaccard coefficient, which is the percentage of nonzero coordinates that differ.
`"spearman"` |  | One minus the sample Spearman’s rank correlation between observations (treated as sequences of values).
@distfun |  | Custom distance function handle. A distance function of the form `function D2 = distfun (XI, YI)`, where XI is a 1×P vector containing a single observation in P-dimensional space, YI is an N×P matrix containing an arbitrary number of observations in the same P-dimensional space, and D2 is an N×P vector of distances, where `(D2k)` is the distance between observations XI and `(YIk,:)`.

`D = pdist (X, Y, Distance, DistParameter)` returns the distance using the metric specified by Distance and DistParameter. The latter one can only be specified when the selected Distance is `"seuclidean"`, `"minkowski"`, and `"mahalanobis"`.

See also: pdist2, squareform, linkage

Source Code: pdist