MATLAB: K-Means: Indices of C in idx

centroidsclusterkmeans

Hello, I'm using the built-in kmeans function but I don't understand a thing. After I've applied the function, I have two output parameters: idx and C. The first one is a matrix containing, for each observation, the cluster's index where it has been classified. The second one is the matrix containing all the centroids location. Well, is there a way to know which are the indices of the centroids C inside the matrix idx? For example, I would like to know the index inside idx of C(:,1), etc.
Thank you very much.

Best Answer

I'm not certain I fully understand your question, but I'll make a guess.
The centroid is not (necessarily) one of the points of the original dataset, so none of the rows of idx correspond to the centroid itself.
The centroid locations are given by the rows of C (not the columns). The row C(1,:) is the centroid for the cluster of points with idx=1. The row C(2,:) is the centroid for the cluster of points with idx=2. And so on.
If that doesn't answer your question, maybe you could comment with some clarification.
Related Question