How can we find out the centroid of each cluster in k-means clustering in MATLAB. Data is quite heterogeneous in nature.So, I want to write some MATLAB code that can plot the centroid of each cluster as well as give the coordinates of each centroid. I have used the following code for clustering-
figure
plot(X(:,1),X(:,2),'.')
opts=statset('Display','final')
[idx,c]=kmeans(x,4,'Distance','cityblock,...
'Replicates',5,'Options',opts)
figure
plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',12)
hold on
plot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',12)
hold on
plot(X(idx==3,1),X(idx==3,2),'g.','MarkerSize',12)
hold on
plot(X(idx==4,1),X(idx==4,2),'y.','MarkerSize',12)
hold on
plot(C(:,1),C(:,2),'Kx',...
'MarkerSize',15,'LineWidth',3)
legend('Cluster 1','Cluster 2','Cluster 3','Cluster 4','Centroids',...
'Location','NW')
title 'Cluster Assignments and centroids '
hold off