function p3rgbl (x, y, z, xlim,ylim,zlim,coff,nc,inifl,sym)
%P3RGB    Plot 3-D scatter plot in RGB colors using current color map.
%         p3rgb(x,y,z,xlim,ylim,zlim,coff,nc,inifl,s) plots 3-D plot in y using current
%         color map. y has to be N-by-3 matrix. Each column contains one
%         dimension. Optional plot symbol is s (see plot).

% Copyright (c) 1994 by Bogdan R. Kosanovic
% University of Pittsburgh, PA, USA

% History: 19-Mar-94 Created

[N, M] = size(x);
%if M ~= 3, error ('invalid number of columns'); end;

if nargin < 10, sym = '-'; end;

map = colormap;
ncols = size(map,1);
if ncols < coff+nc, error ('invalid number of colors'); end;
if N-1 < nc, error ('more colors than line segments'); end;

left = ones(nc,1);
dk = (N-1)/nc;   % how many points with same color
for k = 2:nc, left(k) = ceil((k-1)*dk); end;
left(nc) = min(left(nc),N-1);

if inifl
 clg;
 axis([xlim(1) xlim(2) ylim(1) ylim(2) zlim(1) zlim(2)]); hold on;

 cla;
end;
for ii=1:M
  for k = 1:nc
    head = plot3(0,0,0,sprintf('w%c',sym),'EraseMode','xor');  
    if k < nc, right = left(k+1); else, right = N; end;
    set(head, 'color', map(coff+k,:), 'xdata', x(left(k):right,ii), ...
              'ydata', y(left(k):right,ii), 'zdata', z(left(k):right,ii));
    set(head, 'EraseMode', 'none');
    drawnow;
  end;
end;
hold off;
