Splitting data using kmeans idx
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
KSSV
el 18 de Jun. de 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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!