MATLAB: Clustering Analysis (K-means)

analysisclusterclustersdata analysisdata clusteringk-meanskmeansStatistics and Machine Learning Toolbox

Hi guys, I using the code bellow to extract 3 columns data from an Excel file and cluster it using K-means. I am having trouble however in the analysis part. After I cluster, I get a response from Matlab with the Index number of the cluster for each line in my file, but I am not sure how to use it in order to make the analysis itself.
Example: I want to do a "Histogram" analysis using the fuction "histogram"only in the cluster number 2. How can I do that?
Thanks in Advance !
imp = xlsread('Academia.xlsx')
%Testes de quantidade de clusters:
eva = evalclusters(imp, 'kmeans', 'CalinskiHarabasz','Klist',[1:15])
eva2 = evalclusters(imp, 'kmeans', 'Silhouette','Klist',[1:15])
eva3 = evalclusters(imp, 'kmeans', 'DaviesBouldin','Klist',[1:15])
subplot(2,2,1)
plot(eva)
title('CalinskiHarabasz')
subplot(2,2,2)
plot(eva2)
title('Silhouette')
subplot(2,2,3)
plot(eva3)
title('DaviesBouldin')
%Rodar Kmeans
[idx,C]=kmeans(imp,4)
%Plotagem de gráficos:
[numInst,numDims] = size(imp);
%# show points and clusters (color-coded)
clr = lines(4);
figure, hold on
scatter3(imp(:,1), imp(:,2), imp(:,3), 36, clr(idx,:), 'Marker','.')
scatter3(C(:,1), C(:,2), C(:,3), 100, clr, 'Marker','o', 'LineWidth',3)
hold off
view(3), axis vis3d, box on, rotate3d on
xlabel('flexibilidade'), ylabel('velocidade'), zlabel('forca')

Best Answer

To get points classified as being in cluster #2, do this
cluster2Indexes = idx == 2; % 1-D vector
% Get those points from original data
cluster2Data = imp(cluster2Indexes, :); % 3 column matrix of original data.
I'm not really sure how you want to histogram that N-by-3 matrix of data, but there you have it. Good luck.