0

I have some data

data = 16.9;23.8;11.3;5.8;9;2;8.6;7.3;2.6;0.3;0.9;2.7;1;8.7;4.5;0.4;2.8;8.9;0.4;5;2.7;8.4;3.9;8.8

I did a K-means clustering using this code:

[idx2,C2] = kmeans(firstblik,2,'Distance','cityblock','Replicates',10);
figure;
plot(firstblik(idx2==1),'r.','MarkerSize',12)
hold on
plot(firstblik(idx2==2),'b.','MarkerSize',12)
legend('Cluster 1','Cluster 2','Location','NW')
hold off

the idx2 automatically classifies my data in 2 groups (1 and 2) as such:

idx2 = [2;2;2;2;2;2;2;2;1;1;1;1;1;2;1;2;1;1;1;1;1;2;1;2]

I made a vector of labels for each one of these data points and I would like to show them on my plot.

I tried using the usual text() function for labeling but my k-means plot is split in 2:

I first plot all the 1's then all the 2's in the same figure

How do I label these points considering the labels follow the same order as my data matrix?

any help is appreciated

Thanks!

additional info: my plot is split in 2 so as I already mentioned the text() function won't work because the order of data isn't conserved when plotting idx2

oub
  • 23
  • 1
  • 5
  • possible duplicate of [Data label on each entry in xy scatter](http://stackoverflow.com/questions/7100398/data-label-on-each-entry-in-xy-scatter) – knedlsepp Apr 02 '15 at 10:13
  • I personally would prefer to color the points instead of labeling them though. – knedlsepp Apr 02 '15 at 10:13
  • HI thanks for the help. they are already colored but I need to identify each point individually. I don't think it's a duplicate because I already mentioned me trying the text() function. my problem is that the data is sort of split in 2 so the order is not conserved – oub Apr 02 '15 at 10:56
  • Well, you should specify with what data you want to label the points. If it is with `idx2` it is an exact duplicate. You should specify what exactly the `text` command was that you tried, what it returned but what you expected, because I am sure it can be done with `text`. – knedlsepp Apr 02 '15 at 12:43

1 Answers1

0
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ...
                                      'Replicates',3);

pixel_labels = reshape(cluster_idx,nrows,ncols);

imshow(pixel_labels,[]);
augre
  • 330
  • 3
  • 12
  • Generally, answers are much more helpful if they include an explanation of what the code is intended to do, and why that solves the problem without introducing others. – Tom Aranda Dec 12 '17 at 03:09