MATLAB: What is the best way to create a persistant figure

figureshandlespersistenceplotting

I would like to create a figure that persists between multiple calls to plot data. For example I would like to create the figure and then make several calls at a later time that will update or change the data displayed in that figure. I've thought about doing this one of two ways.
Having a function that creates the figure and plots the data and then returns handles for all the graphics objects it created. On subsequent calls I could then pass the handles back to that function. The existence of these handles would then cause the function to plot using those handles instead of creating new ones.
or
Using the matlab object oriented interface I could make all the handles members of the object and then have the object handle the plotting.
The second option seems more elegant and makes more sense in my head, but I fear that its going to be too slow.
Is there a better way solve this problem?

Best Answer

figure
L(1) = plot(1:10);
hold on
L(2) = plot((1:10).^2);
Now if you want to erase L(1) later:
delete(L(1))
Also note that you can get the handle to the axes and use that with PLOT.