Hi, I have a 732×29 matrix and I would like to cluster the data using kmeasn clustering. The matrix has two clusters (2 classes) that are either 1 or 2 and the 1 or 2 is in the 27th column f the matrix. Here is what I have so far:
fid=fopen('all_classes_withns_dmjd.txt');myimport=textscan(fid,'%s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f','Headerlines',1);fclose(fid);X=cell2mat(myimport(:,2:29));
This works and it imports the code. What do I do to cluster it? I selected the classes like so:
mydata(1:1016,:);X= mydata(1:1016,1);Y= mydata(1:1016,2);scatter(X,Y)
But I think there is a better way, because this way, MATLAB will not automatically make the data 2 clusters.
I tried the code in the website like so, but it does not work! Why?
fid=fopen('all_classes_withns_dmjd.txt');myimport=textscan(fid,'%s %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f','Headerlines',1);fclose(fid);X=cell2mat(myimport(:,2:29));opts = statset('Display','final');[idx,C] = kmeans(X,2,... 'Distance','city',... 'Replicates',5,... 'Options',opts);plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',12)hold onplot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',12)plot(C(:,1),C(:,2),'kx',... 'MarkerSize',12,'LineWidth',2)plot(C(:,1),C(:,2),'ko',... 'MarkerSize',12,'LineWidth',2)legend('Cluster 1','Cluster 2','Centroids',... 'Location','NW')
Thanks!
Best Answer