Agglomerative hierarchical cluster tree
Z = linkage(X)
Z = linkage(X,method)
Z = linkage(X,method,metric)
Z = linkage(X,method,pdist_inputs)
Z = linkage(X,method,metric,'savememory',value)
Z = linkage(Y)
Z = linkage(Y,method)
Z = linkage(
returns
a matrix X
)Z
that encodes a tree of hierarchical
clusters of the rows of the real matrix X
.
Z = linkage(
creates
the tree using the specified X
,method
)method
, where method
describes
how to measure the distance between clusters.
Z = linkage(X,
performs
clustering using the distance measure method
,metric
)metric
to
compute distances between the rows of X
.
Z = linkage(X,
passes
parameters to the method
,pdist_inputs
)pdist
function,
which is the function that computes the distance between rows of X
.
Z = linkage(X,
uses
a memorysaving algorithm when method
,metric
,'savememory'
,value)value
is 'true'
,
and uses the standard algorithm when value
is 'false'
.
Z = linkage(
uses
a vector representation Y
)Y
of a distance matrix. Y
can
be a distance matrix as computed by pdist
,
or a more general dissimilarity matrix conforming to the output format
of pdist
.
Z = linkage(
creates
the tree using the specified Y
,method
)method
, where method
describes
how to measure the distance between clusters.

Matrix with two or more rows. The rows represent observations, the columns represent categories or dimensions.  

Algorithm for computing distance between clusters.
Default:  

Any distance metric that the
Default:  

A cell array of parameters accepted by the  

Either
When Default:  

A vector of distances with the same format as the output of
the


For example, suppose there are 30 initial nodes and at step
12 cluster 5 and cluster 7 are combined. Suppose their distance at
that time is 1.5. Then 
Computing linkage(Y)
can be slow
when Y
is a vector representation of the distance
matrix. For the 'centroid'
, 'median'
,
and 'ward'
methods, linkage
checks
whether Y
is a Euclidean distance. Avoid this timeconsuming
check by passing in X
instead of Y
.
The centroid
and median
methods
can produce a cluster tree that is not monotonic. This occurs when
the distance from the union of two clusters, r and s,
to a third cluster is less than the distance between r and s.
In this case, in a dendrogram drawn with the default orientation,
the path from a leaf to the root node takes some downward steps.
To avoid this, use another method. The following image shows a nonmonotonic
cluster tree.
In this case, cluster 1 and cluster 3 are joined into a new cluster, while the distance between this new cluster and cluster 2 is less than the distance between cluster 1 and cluster 3. This leads to a nonmonotonic tree.
You can provide the output Z
to
other functions including dendrogram
to
display the tree, cluster
to
assign points to clusters, inconsistent
to
compute inconsistent measures, and cophenet
to
compute the cophenetic correlation coefficient.
cluster
 clusterdata
 cophenet
 dendrogram
 inconsistent
 kmeans
 pdist
 silhouette
 squareform