www.gusucode.com > stats 源码程序 matlab案例代码 > stats/CreateHierarchicalClusterTreeFromSampleDataExample.m
%% Create Hierarchical Cluster Tree From Sample Data % This example shows how to create a hierarchical cluster tree from sample % data, and visualize the clusters using a 3-dimensional scatter plot. % Copyright 2015 The MathWorks, Inc. %% % Generate sample data matrices containing random numbers from the standard % uniform distribution. rng default; % For reproducibility X = [gallery('uniformdata',[10 3],12);... gallery('uniformdata',[10 3],13)+1.2;... gallery('uniformdata',[10 3],14)+2.5]; %% % Compute the distances between items and create a hierarchical cluster % tree from the sample data. List all of the items in cluster 2. T = clusterdata(X,'maxclust',3); find(T==2) %% % Plot the data with each cluster shown in a different color. scatter3(X(:,1),X(:,2),X(:,3),100,T,'filled')