Clearing a subplot array of images on a canvas of GUI

1 次查看(过去 30 天)
Hello. I am plotting a set of images whilst in a loop using subplot and its position vector method. In my loop, the values of x and y change. This all works fine and plots to the canvas in my GUI.
positionVector = [os+x, y, width, 0.05];
subplot('Position',positionVector);
hold off;
Does anyone know how to clear this array of images on the canvas??
Thanks Jason

采纳的回答

Geoff Hayes
Geoff Hayes 2014-9-18
Jason - do you wish to clear the image from each subplot, or remove the subplots from the canvas/figure?
One way (for either case) is to manage a list of the handles for each subplots
hSubplots = [];
for
% do stuff
% position subplot
positionVector = [os+x, y, width, 0.05];
h = subplot('Position',positionVector);
% update handle array
hSubplots = [hSubplots ; h];
hold off;
end
Then to delete/remove the subplot from the figure, you would do
delete(hSubplots(k));
for each subplot k. Or if you'd rather just clear the contents from each subplot, use cla
cla(hSubplots(k),'reset');
for each subplot k.
  7 个评论
Jason
Jason 2014-9-18
Thanks Geoff (and Image Analyst). Hmmm, I don't store the h Subplots, so that's my mistake. I will add it to the handles structure. Just out of interest, the subplots I plot are persistent on the canvas so must be stored somewhere - is that true? Jason
Geoff Hayes
Geoff Hayes 2014-9-18
Jason - see Image Analyst's comment to get the handles of all axes (subplots) on the figure. Their "information" is "stored" within the parent figure.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by