%% Script file to show the k-means code % Also shoes the Voronoi Cells % NOTE: The "pause" commands will pause execution until you hit any key! % Random intialization of the data: X=rand(20,2); Temp=randperm(20); NumClusters=4; % Take the first k data points as clusters (k=NumClusters) C=X(Temp(1:NumClusters),:); %% Main code to visualize: plot(C(:,1),C(:,2),'r*',X(:,1),X(:,2),'k.'); pause; %Execution of the code stops until you press any key. for j=1:10 [P,C,Err]=kmeansUpdate(X,C); T(j)=mean(Err); voronoi(C(:,1),C(:,2)); hold on plot(X(:,1),X(:,2),'k.',C(:,1),C(:,2),'r*'); hold off pause; %Code execution pauses- Press any key to continue. end