MATLAB: Is it possible to automate the plotting of data that is created by multiple passes of the same script

MATLABplotting

For example the script runs once and creates a set of data, then runs again (overwriting previous data). I need all data on same plot.
I can save each plot separately and then reassemble once all plots are created, however a simpler way would be preferred so all that would have to be done is running the program and all data would go to the same plot without being overwritten.

Best Answer

Create the axes object with enabling the adding of new lines:
AxesH = axes('NextPlot', 'add', 'Tag', 'ThisIsMyFixedAxes');
When the script runs the next time, it does not create the axes, if it is existing already:
AxesH = findobj('Tag', 'ThisIsMyFixedAxes')
if isempty(AxesH)
AxesH = axes('NextPlot', 'add', 'Tag', 'ThisIsMyFixedAxes');
else
axes(AxesH); % Make it the current axes object
end
Instead of axes(AxesH) it would be smarter to add the axes' handle as a parent in the plot command:
plot(1:10, rand(1, 10), 'Parent', AxesH);