Page 90 - Algorithm Collections for Digital Signal Processing Applications using MATLAB
P. 90

78                                                         Chapter  2
























                            Figure 2-2.  Illustration of K-Means Algorithm





                Figure 2-3.  Data along with the final  centroids obtained by k-means algorithm

              In the above-mentioned example, the data ranges from 0.0067 to 0.9925
           and the six  centroids obtained in the  10 th    iteration are displayed below.
           0.0743    0.2401    0.4364    0.6115    0.7763    0.9603 (see the Figure 2-3).

           3.3      Matlab Program for the K-means Algorithm
                    Applied for the Example given in Section 3.2


              kmeansgv.m
              ________________________________________________________________________

              a=rand(1,100);
              plot(a,zeros(1,100),'*');
              b=rand(1,6);
              for iter=1:1:10
              hold off
              M=[(a-b(1)).^2;(a-b(2)).^2;(a-b(3)).^2;(a-b(4)).^2;(a-b(5)).^2;(a-b(6)).^2;];
              [P,CLUSTERNO]=min(M);
              u=['r','g','b','c','m','y'];
              figure
   85   86   87   88   89   90   91   92   93   94   95