문제

I have the following script for kmeans in Matlab:

load fisheriris
k = 3; 
clusterIndex = kmeans(meas,3);
scatter(meas(:,1),meas(:,2),[],clusterIndex, 'filled') 

How to plot the centroids of each group? Please help!

도움이 되었습니까?

해결책

Straight from the docs:

[IDX,C] = kmeans(X,k) returns the k cluster centroid locations in the k-by-p matrix C

So in your case simply do this:

[clusterIndex, centroids] = kmeans(meas,3);

By the way you might like gscatter, it will colour your clusters nicely for you.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top