Home > chronux_1_50 > spikesort > linec.m

linec

PURPOSE ^

LINEC Plots a line with color varying along its length.

SYNOPSIS ^

function h = linec(x,y,z,c)

DESCRIPTION ^

LINEC             Plots a line with color varying along its length.
   LINEC(X,Y,C) draws the parametric plot Y(k) versus vector X(k) for
   k = 1:length(X) with colors at each vertex given by the vector C
   (scaled into the figure colormap).  The color between vertices is
   interpolated.

   LINEC(Y,C) is equivalent to LINEC(1:length(Y), Y, C).

   LINEC(X,Y,Z,C) plots [X(k), Y(k), Z(k)] with colors given by C(k).

   A patch object is used to actually render the line.  Note that a flaw
   in the Matlab 'painters' renderer causes extremely slow execution on
   some machines when zooming in on these patch 'lines'; for this reason,
   LINEC sets the renderer of the current figure to 'OpenGL'. 

   H = LINEC(...) returns a handle to the line.  The 'line' is actually
   a patch object, so the standard parameter/value pairs used with
   Matlab's builtin PLOT command are not supported.

   Matrix arguments for X,Y are currently not supported.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function h = linec(x,y,z,c)
0002 %LINEC             Plots a line with color varying along its length.
0003 %   LINEC(X,Y,C) draws the parametric plot Y(k) versus vector X(k) for
0004 %   k = 1:length(X) with colors at each vertex given by the vector C
0005 %   (scaled into the figure colormap).  The color between vertices is
0006 %   interpolated.
0007 %
0008 %   LINEC(Y,C) is equivalent to LINEC(1:length(Y), Y, C).
0009 %
0010 %   LINEC(X,Y,Z,C) plots [X(k), Y(k), Z(k)] with colors given by C(k).
0011 %
0012 %   A patch object is used to actually render the line.  Note that a flaw
0013 %   in the Matlab 'painters' renderer causes extremely slow execution on
0014 %   some machines when zooming in on these patch 'lines'; for this reason,
0015 %   LINEC sets the renderer of the current figure to 'OpenGL'.
0016 %
0017 %   H = LINEC(...) returns a handle to the line.  The 'line' is actually
0018 %   a patch object, so the standard parameter/value pairs used with
0019 %   Matlab's builtin PLOT command are not supported.
0020 %
0021 %   Matrix arguments for X,Y are currently not supported.
0022 
0023 %%%%%%%%%%%%%%%%% ARGUMENT CHECKING %%%%%%%%%%%%%%%%%
0024 if (nargin > 4),        error('Only (x,y,z,c) arguments supported.');
0025 elseif (nargin == 4),
0026 elseif (nargin == 3),   c = z;  z = repmat(0,[1,0]);
0027 elseif (nargin == 2),   c = y;  y = x;  x = [1:length(y)]';  z = repmat(0,[1,0]);
0028 else,                   error('At least two arguments are required.');
0029 end
0030 
0031 xlen = length(x);  ylen = length(y);  zlen = length(z);  clen = length(c);
0032 
0033 if (isempty(z))
0034     if (~isequal(xlen,ylen,clen)), error('Vector dimensions must agree.'); end;
0035 else
0036     if (~isequal(xlen,ylen,zlen,clen)), error('Vector dimensions must agree.');  end;
0037 end
0038     
0039 if ((ndims(x) > 2) | (~any(size(x) == 1)) | (ndims(y) > 2) | (~any(size(y) == 1)) | ...
0040     (ndims(z) > 2) | (~any(size(z) == 1)) | (ndims(c) > 2) | (~any(size(c) == 1)))
0041     error('Arguments must be row or column vectors.');
0042 end
0043 
0044 x = x(:); y = y(:);  z = z(:);  c = c(:);    % Force column vectors
0045 
0046 %%%%%%%%%%%%%%%%%%% DO THE WORK %%%%%%%%%%%%%%%%%%%%%
0047 xdata = [x; flipud(x)];
0048 ydata = [y; flipud(y)];
0049 cdata = [c; flipud(c)];
0050 zdata = [z; flipud(z)];
0051 
0052 if (isempty(zdata))
0053     h = patch('XData', xdata, 'YData', ydata, 'CData', cdata);  view(2);
0054 else
0055     h = patch('XData', xdata, 'YData', ydata, 'ZData', zdata, 'CData', cdata');   view(3);
0056 end
0057 set(h, 'EdgeColor', 'interp', 'LineWidth', 2);
0058 set(gcf, 'Renderer', 'OpenGL');
0059 
0060 if (nargout == 0)
0061     clear h
0062 end

Generated on Mon 09-Oct-2006 00:54:52 by m2html © 2003