Clearing a subplot array of images on a canvas of GUI

2 views (last 30 days)
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

Accepted Answer

Geoff Hayes
Geoff Hayes on 18 Sep 2014
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 Comments
Jason
Jason on 18 Sep 2014
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 on 18 Sep 2014
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!