close all; load assignment2.mat; %We try with K=5, since a scatter3 shows that there are 5 visible clusters K1 = 5; cent = Patterns(randperm(size(Patterns,1)),:); centroids1=cent(1:K1,:); %load centroids1.mat; ClusterK1 = kmeans(Patterns,K1,centroids1); colors = colormap('prism'); %We try with K=6, since a scatter3 shows that there are 6 visible clusters K2 = 6; cent = Patterns2(randperm(size(Patterns2,1)),:); centroids2=cent(1:K2,:); ClusterK2 = kmeans(Patterns2,K2,centroids2); colors = colormap('prism'); %DBSCAN method Eps1 = 0.9; MinPts1 = 5; ClusterEps1 = dbscan(Patterns,Eps1,MinPts1); colors = colormap('prism'); Eps2 = 0.9; MinPts2 = 5; ClusterEps2 = dbscan(Patterns2,Eps2,MinPts2); colors = colormap('prism'); %Draw graphs hold on for i=1:K1 scatter3(Patterns(find(ClusterK1 == i),1),Patterns(find(ClusterK1 == i),2),Patterns(find(ClusterK1 == i),3), '-', colors(i,:)) end %Start new figure figure hold on for i=1:K2 scatter3(Patterns2(find(ClusterK2 == i),1),Patterns2(find(ClusterK2 == i),2),Patterns2(find(ClusterK2 == i),3), '-', colors(i,:)) end %Start new figure figure hold on [PC, SCORE, LATENT] = princomp(Patterns); for i=1:max(ClusterEps1) scatter3(SCORE(find(ClusterEps1 == i),1),SCORE(find(ClusterEps1 == i),2),SCORE(find(ClusterEps1 == i),3), '-', colors(i,:)) end %Start new figure figure hold on [PC, SCORE, LATENT] = princomp(Patterns2); for i=1:max(ClusterEps2) scatter3(SCORE(find(ClusterEps2 == i),1),SCORE(find(ClusterEps2 == i),2),SCORE(find(ClusterEps2 == i),3), '-', colors(i,:)) end