k-means - missing to plot some data points

1 vue (au cours des 30 derniers jours)
Berk
Berk le 21 Avr 2013
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)

Réponse acceptée

Tom Lane
Tom Lane le 22 Avr 2013
I think they're just clipped at the boundary of the plot. Try adding this:
xlim([.9 3.1]); ylim([.9 8.1])

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by