k-means - missing to plot some data points
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Tom Lane
on 22 Apr 2013
I think they're just clipped at the boundary of the plot. Try adding this:
xlim([.9 3.1]); ylim([.9 8.1])
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!