clear;
close all;
load clustdata.mat;

X=X1;
for k=2:5
  J_min = +inf;
  for trial=1:5
    y = kmeans(X,k);
    J = kmeans_metric(y,X);
    if (J < J_min)
      J_min = J;
      plotclust(X,y);
      refresh;
      eval(sprintf('print -depsc hw5prob3_2_X1_%d.eps',k));
    end
  end
end


X=X2;
for k=2:5
  J_min = +inf;
  for trial=1:5
    y = kmeans(X,k);
    J = kmeans_metric(y,X);
    if (J < J_min)
      J_min = J;
      plotclust(X,y);
      refresh;
      eval(sprintf('print -depsc hw5prob3_2_X2_%d.eps',k));
    end
  end
end

X=X3;
for k=2:5
  J_min = +inf;
  for trial=1:5
    y = kmeans(X,k);
    J = kmeans_metric(y,X);
    if (J < J_min)
      J_min = J;
      plotclust(X,y);
      refresh;
      eval(sprintf('print -depsc hw5prob3_2_X3_%d.eps',k));
    end
  end
end
