Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Question about k means clustering

Asked by John

John (view profile)

on 16 Nov 2011
Accepted Answer by bym

bym (view profile)

Hi there,

After you have clustered data, how can you find out or get a print out of what cluster each point has been assigned to?

For example if I cluster this simple data, how can I find out which cluster each data point belongs to

X = [randn(100,2)+ones(100,2);...
   randn(100,2)-ones(100,2)];
opts = statset('Display','final');
[idx,ctrs] = kmeans(X,2,...
                  'Distance','city',...
                  'Replicates',5,...
                  'Options',opts);
plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',12)
hold on
plot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',12)

Thank you

0 Comments

John

John (view profile)

Tags

Products

No products are associated with this question.

2 Answers

Answer by bym

bym (view profile)

on 17 Nov 2011
Accepted answer

Isn't it the

idx

variable which you have plotted in different colors?

0 Comments

bym

bym (view profile)

Answer by John

John (view profile)

on 17 Nov 2011

Yes it is! Thanks

0 Comments

John

John (view profile)

Contact us