% K-means example
clear all

% Simple example that we did on the quiz.
data = [6 2; 4 4; 5 7; 7 7; 8 4; 14 3; 18 3; 14 6; 18 6];
plot(data(:,1), data(:,2), 'ko');
axis([0 20 0 15]) 
hold on

k = 2; % Hard-coded for this example.
% Could use means = rand(k,2) to get random means;
means = [3 6; 9 2]
plot(means(:,1), means(:,2), 'r+');
iter = 0;
iterString = sprintf('%d', iter);
text(means(:,1), means(:,2), iterString);


% Algorithm:
% Run until convergence. For simplicity, we hardcode the number of
% iterations.
numIters = 1
nPoints = size(data, 1);

for iter = 1:numIters    
    % 1. Find the mean closest to each data point
    
    % 2. Re-compute the cluster means
    
    plot(means(:,1), means(:,2), 'r+');
    iterString = sprintf('%d', iter);
    text(means(:,1), means(:,2), iterString);

    
end





