13 lines
544 B
Text
13 lines
544 B
Text
>load clustering.e
|
|
Functions for clustering data.
|
|
>np=5; m=3*normal(np,2);
|
|
% Spread n points randomly around these points.
|
|
>n=5000; x=m[intrandom(1,n,np)]+normal(n,2);
|
|
% The function kmeanscluster contains the algorithm. It returns the
|
|
% indices of the clusters the points contain to.
|
|
>j=kmeanscluster(x,np);
|
|
% We plot each point with a color representing its cluster.
|
|
>P=x'; ...
|
|
> plot2d(P[1],P[2],r=totalmax(abs(m))+2,color=10+j,points=1,style="."); ...
|
|
> loop 1 to k; plot2d(m[#,1],m[#,2],points=1,style="o#",add=1); end; ...
|
|
> insimg;
|