필터 지우기
필터 지우기

k-means - missing to plot some data points

조회 수: 3 (최근 30일)
Berk
Berk 2013년 4월 21일
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)

채택된 답변

Tom Lane
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by