Save multiple handles in a figure

5 views (last 30 days)
I have a program that produces multiple individual plots
for i=1:n
...
h(i)=plot(Q,dP,'Color',ColorSet(i,:),'LineWidth',0.5);
end
In the end I want to plot to plot all the handles on top of eachother. How can I do this?
Keep in mind the loop consists of alot of data so to keep the memory on the computer low it is cleared each loop
I have tried with
saveas(h(:),strcat('Summary plots\',char(title_plot),'.png'))
But it does not seem to work

Accepted Answer

Walter Roberson
Walter Roberson on 11 Jan 2014
Easiest way: instead of writing them in the figure they are going into now, create a new figure and a new axis and plot them all in that axes, and then at the end saveas() the figure.
If there is a reason why you want them plotted in an existing figure, then if you can, create a uipanel at the area to be plotted into, and have the axes created in the uipanel and the plots done in that axes. Then when it is time to save the plot, create a new figure and change the Parent property of the uipanel to be the new figure; then saveas() the new figure.
If you cannot create a uipanel then if you are not using subplot() or legend() or colorbar() or the mapping toolbox (or more technically, if everything is going into a single axes), then when it is time to save the plot, create a new figure, and change the Parent property of the axes to be the new figure, then saveas() the new figure. The advantage of the uipanel() version over this version is that the uipanel() version can use multiple axes.
The above techniques move the graphics to a new figure, without copying the graphics. If it is necessary to keep the graphics where they are, then most efficient would be to Parent back afterwards. But if you cannot do that, then at time to save, create a new figure, and copyobj() all axes into it (remember, some of them may have hidden handles if you used legend() etc.) Then saveas() the new figure and destroy the figure afterwards. This process will duplicate the graphics memory as you go, which could be a problem if you have a lot of data being plotted.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!