try doing plot(1:i,X(1:i)); instead of line(i,X(i)); Edit: You wouldn't need to do hold on; with this method either....

matlab,plot,colorbar,line-plot

A way to color the lines in a way corresponding to the colorbar where you build you own colormap can be found at http://www.mathworks.com/matlabcentral/newsreader/view_thread/256087...