% % Examples 9.15 and 9.17 % % epage 392 (cluster/ % % Written by: % -- % John L. Weatherwax 2008-02-20 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- clear all; close all; clc; addpath('../../Code/CSTool'); %-- % First Example 9.15: %-- % Let's make up a data set - 2-D. x = [1 1; 1 2; 2 1; -1 -1; -1 -2]; plot(x(:,1),x(:,2),'kx') % plots the points. axis([-3 3 -3 3]) text(x(:,1)+.1,x(:,2)+.1,'1|2|3|4|5'); % Find the Euclidean distance using pdist. % Convert to matrix form for easier reading. ye = pdist(x,'euclid'); %ye_mat = squareform(ye); ze_link = linkage(ye); fprintf('the found clustering array T is\n'); %T = cluster(ze_link,'maxclust',3); T = cluster(ze_link,'maxclust',2); T % color the points according to what cluster they are in ... uT = unique(T); nu = length(unique(T)); colors = 'rbkmc'; for ii=1:nu, inds=find(T==uT(ii)); plot( x(inds,1),x(inds,2),['o',colors(ii)] ); hold on; end axis([-3 3 -3 3]) fprintf('print the inconsistent values of a cluster tree ... \n'); inconsistent(ze_link)