Code covered by the BSD License  

Highlights from
3D colored line plot

image thumbnail

3D colored line plot


Georg Stillfried


06 Apr 2009 (Updated )

Plot 3D lines with CData, (actually surface)

color_line3(x, y, z, c, varargin)
function h = color_line3(x, y, z, c, varargin)
% color_line3 plots a 3-D "line" with c-data as color
%       h = color_line(x, y, z, c)
%       by default: 'LineStyle','-' and 'Marker','none'
%          or
%       h = color_line(x, y, z, c, mark) 
%          or
%       h = color_line(x, y, z, c, 'Property','value'...) 
%             with valid 'Property','value' pairs for a surface object
%  in:  x      x-data
%       y      y-data
%       z      z-data
%       c      4th dimension for colouring
%       mark   for scatter plots with no connecting line
% out:  h   handle of the surface object

h = surface(...
  'XData',[x(:) x(:)],...
  'YData',[y(:) y(:)],...
  'ZData',[z(:) z(:)],...
  'CData',[c(:) c(:)],...
if nargin ==5
    switch varargin{1}
        case {'+' 'o' '*' '.' 'x' 'square' 'diamond' 'v' '^' '>' '<' 'pentagram' 'p' 'hexagram' 'h'}
            error(['Invalid marker: ' varargin{1}])

elseif nargin > 5

Contact us