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

3 views (last 30 days)
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.
  1 Comment
Adam
Adam on 26 Oct 2015
Just change your script into a function and do the plotting in a script or function that then calls it multiple times.
You could probably still do that with a script, but depending what is in the script it may be more complicated. Functions are generally better than scripts, especially if you want to do the same thing repeatedly, but with different data.

Sign in to comment.

Accepted Answer

Jan
Jan on 26 Oct 2015
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);

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!