I’m clustering the rows of an NxM matrix using kmeans.
clustIdx = kmeans(data, N_CLUST, 'EmptyAction', 'drop');
I then re-arrange the rows of my matrix to such that adjacent rows are in the same cluster
dataClustered = data(clustIdx,:);
However every time I run the cluster analysis I get more or less the same clusters but with different identities. Thus the structure in dataClustered looks the same after each iteration but the groups are in different orders.
I’d like to re-arrange my cluster identities such that the the lower cluster identities represent dense clusters and the higher numbers are the sparse clusters.
Is there a easy and/or intuitive way to do this?
ie. Convert
clustIdx = [1 2 3 2 3 2 4 4 4 4];
to
clustIdx = [4 2 3 2 3 2 1 1 1 1]
The identities themselves are arbitrary the information is contained in the grouping.
If I understand correctly, you want to assign cluster label 1 to the cluster with most points, cluster label 2 to the cluster with the second most points, etc.
Assume you have a cluster label array called
idxNow you can relabel idx like this: