function [cidx,ctrs]=test1_kmeans(X,names,k);
%function [cidx,ctrs]=test1_kmeans(X,names,k);
% Compute kmeans clustering labels (cidx) and centroids (ctrs)
% clustering of columns of X

% Matlab version. very slow
  opts = statset('Display','final');
 [cidx, ctrs] = kmeans(X, k, 'Distance','sqEuclidean', ...
                               'Replicates',5, 'Options',opts);
ctrs=full(ctrs');
if (isempty(names))
for j=1:k,
   fprintf('-----------\n')
   fprintf('group %d\n',j)
   fprintf('-----------\n')
   disp([int2str(find(cidx==j))])
end
else
for j=1:k,
   fprintf('-----------\n')
   fprintf('group %d\n',j)
   fprintf('-----------\n')
   disp([int2str(find(cidx==j)), names(cidx==j,:)])
   %disp([int2str(find(cidx'==j)), names(cidx==j,:)])
end
end

   fprintf('-----------\n')
   fprintf('-----------\n')
fprintf('centroids\n')
disp([(1:k)',ctrs'])
return 
