Counting How Many Cluster Index

조회 수: 1 (최근 30일)
Alvi Syahrin
Alvi Syahrin 2013년 5월 24일
I am doing clustering with k-means, and here is the code:
[g c] = kmeans(data,k,'dist','SqEuclidean');
g is the cluster index
c is the centroid
k is the number of clusters, I input '3' in it.
When the code is executed, here is the sample result:
40 60 69 1
50 75 78 2
65 70 75 2
79 80 72 3
88 80 80 3
36 67 66 1
40 60 69 1
77 85 65 3
76 77 79 3
My question is, how to count the cluster index for each cluster? What script I should write to show this thing:
"Cluster1 has three members
Cluster2 has two members
Cluster3 has four members"
I'm getting confused because the cluster index only have one variable. Any idea?
Thank you.

답변 (1개)

Tom Lane
Tom Lane 2013년 5월 24일
Look at these, and see if it helps:
unique(g)
find(g==3)
  댓글 수: 1
Alvi Syahrin
Alvi Syahrin 2013년 5월 24일
Thank you. Anyway, it is working with accumarray function. ^_^

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Cluster Analysis and Anomaly Detection에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by