www.gusucode.com > stats 源码程序 matlab案例代码 > stats/CreateHierarchicalClusterTreeUsingWardsLinkageExample.m

    %% Create Hierarchical Cluster Tree Using Ward's Linkage
% This example shows how to create a hierarchical cluster tree using Ward's
% linkage, and visualize the clusters using a 3-dimensional scatter plot.

% Copyright 2015 The MathWorks, Inc.


%%
% Create a 20,000-by-3 matrix of sample data generated from the standard
% uniform distribution.
rng default;  % For reproducibility
X = rand(20000,3);

%%
% Create a hierarchical cluster tree from the sample data using Ward's
% linkage. Set |'savememory'| to |'on'| to construct clusters without
% computing the distance matrix.
c = clusterdata(X,'linkage','ward','savememory','on','maxclust',4);

%%
% Plot the data with each cluster shown in a different color.
scatter3(X(:,1),X(:,2),X(:,3),10,c)