   function [ctrs,idx] = myKmeans(X,ND,max_its,tol)
%% function [ctrs,idx] = myKmeans(X,ND,max_its,tol)
     if (nargin < 4)
       tol = 1.e-04;
     end
     b_plt = 1;     
     if (b_plt)
       scatter(X(:,1),X(:,2),'o')
       hold on;
     end
     
     if (nargin < 3)
       max_its = 20;
     end
     ctrs = zeros(ND,size(X,2)); 
     idx = randperm(size(X,1));
     ctrs = X(idx(1:ND), :);
     
     for i=1:max_its
%%-------------------- scatter plot of new centroids
       ctrO = ctrs;
       if (b_plt)
	 h=scatter(ctrs(:,1),ctrs(:,2),'s','filled');
	 set(h,'LineWidth',3)
	 pause(0.5)
       end
       idx  = getClosestCtrs(X, ctrs);
       ctrs = getCentroids(X, idx, ND);
       if (norm(ctrO - ctrs)< tol*norm(ctrs)), break, end
     end

     idx  = getClosestCtrs(X, ctrs);
