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

    %% Compute Silhouette Values  
% Compute the silhouette values from clustered data.   

%% 
% Generate random sample data. 
rng default  % For reproducibility
X = [randn(10,2)+ones(10,2);randn(10,2)-ones(10,2)];  

%% 
% Use |kmeans| to cluster the data in |X| based on the sum of absolute differences
% in distance. 
cidx = kmeans(X,2,'distance','cityblock');  

%% 
% Compute the silhouette values from the clustered data. Specify |metric|
% as |'cityblock'| to indicate that the |kmeans| clustering is based on
% the sum of absolute differences. 
s = silhouette(X,cidx,'cityblock')