Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Pairwise distance between two sets of observations

`D = pdist2(X,Y,Distance)`

`D = pdist2(X,Y,Distance,DistParameter)`

`D = pdist2(___,Name,Value)`

`[D,I] = pdist2(___,Name,Value)`

returns the distance using the metric specified by `D`

= pdist2(`X`

,`Y`

,`Distance`

,`DistParameter`

)`Distance`

and `DistParameter`

. You can specify
`DistParameter`

only when `Distance`

is `'seuclidean'`

, `'minkowski'`

, or
`'mahalanobis'`

.

specifies an additional option using one of the name-value pair arguments
`D`

= pdist2(___,`Name,Value`

)`'Smallest'`

or `'Largest'`

in
addition to any of the arguments in the previous syntaxes.

For example,

`D = pdist2(X,Y,Distance,'Smallest',K)`

computes the distance using the metric specified by`Distance`

and returns the`K`

smallest pairwise distances to observations in`X`

for each observation in`Y`

in ascending order.`D = pdist2(X,Y,Distance,DistParameter,'Largest',K)`

computes the distance using the metric specified by`Distance`

and`DistParameter`

and returns the`K`

largest pairwise distances in descending order.

`[`

also returns the matrix `D`

,`I`

] = pdist2(___,`Name,Value`

)`I`

using any of the arguments in the
previous syntaxes. The matrix `I`

contains the indices of the
observations in `X`

corresponding to the distances in
`D`

.

`ExhaustiveSearcher`

| `KDTreeSearcher`

| `createns`

| `knnsearch`

| `pdist`

Was this topic helpful?