@ -27,17 +27,9 @@ centroids = zeros(K, n);
%
for k = 1:K
count = 0;
X_in_k = X(idx == k, :);
if size(X_in_k, 1) > 0
% XXX vectorize
centroids(k, :) = sum(X_in_k)/size(X_in_k, 1);
for i = 1:m
if idx(i) == k
centroids(k, :) += X(i, :);
count += 1;
end
if count > 0
centroids(k, :) /= count;