Splitting data using kmeans idx
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm using the built-in kmeans function and want to split the given data X based on the cluster it belongs to. For example, if I choose k = 5, then I want to put append all of the X data corresponding to cluster 1 into one matrix. What's the best way to do this?
0 commentaires
Réponses (1)
KSSV
le 18 Juin 2018
Check the below demo code:
% A random data
N = 10000 ;
x = rand(N,1) ;
y = rand(N,1) ;
% Number of classes
NC = 10 ;
% apply kmeans
idx = kmeans([x y],NC) ;
% cluster the data
data= cell(NC,1) ;
figure
hold on
for i = 1:NC
data{i} = [x(idx==i),y(idx==i)] ;
plot(data{i}(:,1),data{i}(:,2),'.','color',rand(1,3))
end
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!