% Script file for clustering with SAT data

clear all,close all
load satdata

% Perform Principal Components Analysis
mat = [m v pct];
[pcs,newdata] = princomp(mat);

% Perform clustering
Y = pdist(newdata);
Z = linkage(Y);    % OR G = clusterdata(newdata,2)
G = cluster(Z,2);

% Grouped scatter plot based on clustering
gscatter(m,v,G,'br','+x')

% Use dendrogram to detect number of clusters
figure
dendrogram(Z,'colorthreshold',Z(end,end)-eps)