How do I Create an array of plots. The results disapear into "handle to deleted PolarCompassPlot" See code

46 views (last 30 days)
clearvars -except Radius_list Six_plots
Circle_num = 4
nlist = 1;
%Six_plots = F_six_plots(Circle_num, Radius_list);
Six_plots;
sz = size(Six_plots,2);
Plot_num(1:sz) = compassplot(ones)
jplot = 1;
while jplot < sz
Plot_num(nlist) = compassplot(Six_plots(1:nlist));
nlist = nlist+1;
jplot = jplot+1
end
X = Plot_num
Stepping thru the while works. Plot_num(nlist) is fine
X is all "handle to deleted PolarCompassPlot"

Answers (1)

Walter Roberson
Walter Roberson on 19 Dec 2025 at 7:59
You are calling compassplot() in a loop.
By default, each call to compassplot() removes all existing graphics on the axes -- so each call to compassplot() is deleting the previous compassplot()
You have four options:
  1. Use hold on before the while loop. That will cause the various compassplot() to accumulate onto the same axes. As you are not providing x values distinct from y values to the various compassplots(), this would result in all of the compassplot() sharing the same axes and getting tangled with each other. That is potentially a problem (but might be what you want.)
  2. Use figure or uifigure inside the while loop but before the compassplot() call. This will result in completely different figures being generated for the various compassplot()
  3. Use subplot() before each compassplot() call (including before the one before the loop). subplot() creates distinct graphics axes for the content to go into.
  4. Use tiledlayout() before the first compassplot() call, and then nexttile() before each compassplot() call. nexttile() creates distinct graphics axes for the content to go into, but does so in a nicer more modern way than subplot() does
  8 Comments
Norman
Norman 1 minute ago
Edited: Norman less than a minute ago
set(cp, 'DeleteFcn', '???')
I think the documentation says that this will stop the deletion. Correct?
What do I use for ???
Walter Roberson
Walter Roberson 25 minutes ago
The DeleteFcn is executed when there is a request to delete the component. It gives an opportunity to manage resources. After the DeleteFcn is executed, the properties of the object will be cleared.
There is no opportunity to stop deletion of the object.
The closest to being able to stop deletion, is that figures and uifigures have a CloseRequestFcn callback. The CloseRequestFcn is called if the user (or code) calls close() on the figure or uifigure, or if the user uses the window decorations to request closing the window. The CloseRequestFcn must call delete() if it wants the close to actually happen; if it does not call delete() then the figure or uifigure will stay open. This has nothing to do with the automatic clearing of axes that is normally done if hold is not on but you request a "top-level" graphics operation.

Sign in to comment.

Categories

Find more on Printing and Saving in Help Center and File Exchange

Tags

Products


Release

R2025b

Community Treasure Hunt

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

Start Hunting!