% LOLLIPOP: Produces 3D scatterplot in which points are anchored onto the 
%           X,Y plane by a stem (subtended line).  Does not open a new figure window.
%
%     Syntax:  lollipop(x,y,z)  OR  lollypop([x,y,z])
%
%           x,y,z = column vectors of identical length.
%

% RE Strauss, 2/18/98
%   11/25/99 - changed plot colors for Matlab v5.
%   8/23/01 -  added box statement for Matlab v6.

function lollipop(x,y,z)
  if (nargin==1)
    z = x(:,3);
    y = x(:,2);      
    x = x(:,1);
  end;

  if (length(x)~=length(y) | length(x)~=length(z))
    error('  LOLLIPOP: input vectors must be equal in length');
  end;

  xmin = min(x);
  xmax = max(x);
  ymin = min(y);
  ymax = max(y);
  zmin = min(z);
  zmax = max(z);

  deltax = 0.05*(xmax-xmin);
  deltay = 0.05*(ymax-ymin);
  deltaz = 0.05*(zmax-zmin);

  xmin = xmin - deltax;
  xmax = xmax + deltax;
  ymin = ymin - deltay;
  ymax = ymax + deltay;
  zmin = zmin - deltaz;
  zmax = zmax + deltaz;

  plot3(x,y,z,'ko');
  axis([xmin xmax ymin ymax zmin zmax]);
  hold on;
  
  for i=1:length(x)
    plot3([x(i) x(i)],[y(i) y(i)],[0 z(i)],'k-');
  end;

  box on;
  hold off;

  return;

