   function ctrs = getCentroids(X, idx, nC)
%% function ctrs = getCentroids(X, idx, nC)    
%% computes centroids given labels (idx)
  [m n] = size(X);
  ctrs = zeros(nC, n);
  for i=1:nC
      xi = X(idx==i,:);
      if (size(xi,1) == 0)
        j = randperm(m,1);
        ctrs(i,:) = X(j,:);
      else
        ctrs(i,:) = mean(xi);
      end
  end

