clear all; close all;
centers  = [0 0; 5 5]';
[n Ncenters] = size(centers);

m = 50;
examples = [];
for i = 1:Ncenters
    scatters = repmat(centers(:,i),1,m) + randn(n,m);
    examples = [examples scatters]; %#ok<AGROW>
end
clear scatters;
m = length(examples(1,:));
plot(examples(1,:),examples(2,:),'.');
hold on;

us = my_kmeans(examples,2);
markers = {'ro'; 'ko'};
for j = 1:2
    plot(us(1,j),us(2,j),markers{j},...
            'MarkerSize',8);
    for i = 1:m
        idx = 1 + (norm(examples(:,i)-us(:,1)) > ...
                   norm(examples(:,i)-us(:,2)));
        plot(examples(1,i),examples(2,i),...
                markers{idx},'MarkerSize',8);
    end
end