+3  A: 

When you call plot multiple times on the same figure, the previous plot is by default erased, and the handle to the previous plot points to nothing. Thus the error.

To fix this, you need to set the NextPlot property of the axes to add. You can do this by calling hold on (that's what you'd do if you were plotting from command line), or you can write

fig=figure;
%# create a set of axes where additional plots will be added on top of each other 
%# without erasing
axes('NextPlot','add');

If you want, you can store the axes handle as well, and use plot(ah,x,y,...) to make sure that you plot into the right set of axes and not somewhere strange if you happen to click on a different figure window between the time the figure is opened and the plot command is issued.

Jonas
See edits at bottom of my post.
pinnacler
Can I also set 'hold on' for each axis or is that for the entire figure or nothing.
pinnacler
Hold on works for the current axes. If there is no current axes, Matlab creates a set of axes and sets its `NextPlot` property to `add`. `hold on` and `hold of` are simply shortcuts for `set(gca,'NextPlot','add')` and `set(gca,'NextPlot','replace')`. `gca` gets the handle of the current axes, i.e. the axes you last clicked on, or the first axes in the last figure you clicked on.
Jonas
That worked great. Thanks... Are there any good resources for someone experienced with programming but not with matlab? This language seems very quirky...
pinnacler
@pinnacler: Stackoverflow is pretty good, since programmers usually know how to ask questions, and good questions get fast answers. Also, the Matlab documentation is very useful. Furhtermore, I give a presentation about Matlab to programmers next Tuesday (see also this question:http://stackoverflow.com/questions/2691569/matlab-tutorial-for-programmers), and if you want to come over to Montral, you're very welcome :). If you contact me via my page at the Mathworks file exchange, I can send you what I'm presenting. It may be a good start.
Jonas
How much is the workshop in Montreal? I may make the trip... seriously. I'm in Boston, that's the closest I'll ever be.
pinnacler
Jonas