%% Script file to show the k-means code % 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: for j=1:10 [P,C,Err]=kmeansUpdate(X,C); T(j)=sum(Err); end plot(T); legend('Distortion Error per Iterate');