Clearing Subplots & getting the original view
18 views (last 30 days)
Show older comments
Varun Jadhav
on 20 Nov 2015
Commented: Varun Jadhav
on 25 Nov 2015
Hi,
In my GUI, on pushing a button, I split one "axes" (handle: plot) into 3 subplots (ax1, ax2, ax3); & once I have done this, I clear it using the commands: cla(ax1);cla(ax2);cla(ax3).
But if I click on the pushbutton again; MATLAB crashes.
I tried debugging, it gives an error when executing the axes handle: axes(handles.plot);
Is it because the axes is still divided into 3 subplots???
Because when I tried clearing the axes using: cla(handles.plot, 'reset'); I get an error: Bad Handle.
Is there a way to clear subplots and plot on that area again on clicking the pushbutton?
Or is there a way to clear the subplots by calling the tag of the parent axes?
Please advise on this.
0 Comments
Accepted Answer
Walter Roberson
on 20 Nov 2015
subplot() does not "split" or subdivide an existing axes. subplot() uses its parameters to figure out where on the figure the desired axes should be positioned. Then subplot looks at all over the other axes in the figure, and if it finds that any of them would be covered over by the new axes, then it deletes the old axes. So if you had
plot(rand(1,20))
subplot(1,2,1)
then the subplot() would notice that it was covering over the axes that had the plot() in it and it would delete the old axes, and the plot would be gone.
Thus, if you want to restore back to the single axes after you have done a subplot(), you need to create it again.
There is a way to save the content of an axes and restore it later. Two ways, actually:
1) You can use hgsave() and later hgload() to save the object in a .mat file and restore a copy of it when needed. This is not usually done except when creating .fig files; OR
2) You can create a figure whose visibility is set off, and set the Parent property of the axes to be the new figure. This will preserve the axes and contents exactly as-is, just not visible. Later when you want to restore it, you can set its Parent property back to be the original figure. You can hide any number of objects in the same invisible figure. Keep in mind, though, that the saved objects take up memory.
More Answers (0)
See Also
Categories
Find more on Specifying Target for Graphics Output 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!