Consider the following example of a 3D point moving along a helix-shaped path over time:
%# data
t = linspace(0,8*pi,200);
x = 20*t; y = cos(t); z = sin(t);
%# plot 3D line
plot3(x,y,z)
axis tight, grid on, view(35,40)
Now if you want to draw a multi-colored line, the naive solution would be to write a for-loop, drawing each small segment as a separate line, each having a different color. This is because a single line object can only have one color.
A better approach is to use a surface graphics object:
c = 1:numel(t); %# colors
h = surface([x(:), x(:)], [y(:), y(:)], [z(:), z(:)], ...
[c(:), c(:)], 'EdgeColor','flat', 'FaceColor','none');
colormap( jet(numel(t)) )
The result:
