function show_hiercluster(X,C);

[m n] = size(X);
if n ~= 2, error('Demo only works in 2D.'); end

% for display purposes
x = X(:,1);
y = X(:,2);
xmin = min(x);
xmax = max(x);
ymin = min(y);
ymax = max(y);
xrange = xmax-xmin;
yrange = ymax-ymin;
ax = [xmin-xrange/8 xmax+xrange/8 ymin-yrange/8 ymax+yrange/8];

% draw points
plot(x,y,'.','markersize',10);
axis(ax);
hold on;

X(2*m-1,:)=0;
h = zeros(1,m-1);
for k=m+1:2*m-1
  X(k,:) = mean(X(C.points{k},:),1);
  i = C.points{k};
  j = [];
  for l=1:length(i)
    j = [j reshape([i(l)*ones(1,length(i)-l);i(l+1:end)],1,2*(length(i)-l))];
  end
  h(k-m) = plot(X(j,1),X(j,2),'b-');
  drawnow
  %pause(.01);
  %set(h(k-m),'visible','off');
end
hold off

while ( 1 )
  k = input('Enter number of clusters, or q to quit: ','s');
  if length(k)==0 || k(1)=='q', 
    return;
  else
    k = str2num(k);
    set(h(1:m-k),'visible','on');
    set(h(m-k+1:m-1),'visible','off');
  end
end
