k-means - missing to plot some data points
1 回表示 (過去 30 日間)
古いコメントを表示
I am using k-means to cluster 13 data points (X) into 3 clusters with the following code. However, when plotting the data points and cluster centers some of the data points disappear?
figure
mSize = 24;
hold on
X = [1 1;1 2;1 3;1 5;2 3;2 4;2 5;3 1;3 2;3 3;1 8;2 7;3 7]; % Data vector
[idx,ctrs] = kmeans(X,3); % cluster X into three clusters
plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',mSize)
plot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',mSize)
plot(X(idx==3,1),X(idx==3,2),'k.','MarkerSize',mSize)
plot(ctrs(1,1),ctrs(1,2),'kx', 'MarkerSize',mSize,'LineWidth',2)
plot(ctrs(2,1),ctrs(2,2),'ko', 'MarkerSize',mSize,'LineWidth',2)
plot(ctrs(3,1),ctrs(3,2),'k^', 'MarkerSize',mSize,'LineWidth',2)
0 件のコメント
採用された回答
Tom Lane
2013 年 4 月 22 日
I think they're just clipped at the boundary of the plot. Try adding this:
xlim([.9 3.1]); ylim([.9 8.1])
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!