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

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"

Respuestas (1)

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 comentarios

Plot_num(nlist) = compassplot(Six_plots(1:nlist));
nlist = nlist+1;
The action of that code would be to create multiple plots, each one starting from the beginning of the data, and adding one additional point each time (drawing from the beginning of the data each time), but saving each of the plot handles.
It seems unlikely that is what you want to do.
If you have reason to want to animate the drawing of the compassplot() then normally what you would do is first
cp = compassplot([]);
and then loop,
%do NOT make any more compassplot() calls inside the loop!
set(cp, 'theta', ThetaData(1:nlist), 'rho', SixPlots(1:nlist));
drawnow();
where ThetaData is a new variable that indicates the various theta that you want to draw the points at.
Nothing seems to work.
How do I use ThetaData? does it hold the plot after the deletion "error undefined variable" I tried creating it it as a handle? ?????????????????????????????????
There is DeleteFcn which I do not know how to use. (I tried everything)
Th documentation seems to indicate that it can stop the deletion of the plot after each call to compassplot
hours spent no where
I can cee the plots being created, only forthem disapear
I can see the data while in the loop working. The plots are there. Then poof gone. HOURS spent. Nothing works.
set(cp, 'theta', ThetaData(1:nlist), 'rho', SixPlots(1:nlist));
Do I need to reate a ThetaData? "error undefined" If so what type is it, Handle to compassplot???, 0,1????
?????????????????????/
Can DeleteFcn be used to stop the deletion until I can save it. If so , how do I use it?
Can you describe in words what you are trying to accomplish? Is the end goal separate and distinct plots built from subsets of the same data set? Is the end goal a single, animated plot? Something else?
It would be nice if some example SixPlots data is provided (can save to a .mat file and upload that using the Paperclip icon in the Insert menu)
Here is some sample code that implements a few of the ideas that @Walter Roberson suggested. Maybe one will resonate.
Create some example data
theta = 0:60:300;
rho = 1:6;
SixPlots = rho.*(cosd(theta)+1j*sind(theta));
One figure, one polar axis, with six arrows
figure
P1 = compassplot(SixPlots);
One figure, six polar axes, each with one arrow
figure;
t = tiledlayout(3,3);
for ii = 1:6
nexttile
P2(ii) = compassplot(SixPlots(ii));
end
Warning: Plotting the real and imaginary components of the value provided. Specify both R and Theta values if you do not intend to plot a complex value.
Warning: Plotting the real and imaginary components of the value provided. Specify both R and Theta values if you do not intend to plot a complex value.
set([P2.Parent],'RLim',[0,6]);
One figure, one axes, six arrows, each arrow added in a loop by updating the properties of the plot, for an animated effect (not seen here on Answers). Note that for this to work we have to make the first plot with the first data point, not an empty input as suggested above.
figure
P3 = compassplot(SixPlots(1));
Warning: Plotting the real and imaginary components of the value provided. Specify both R and Theta values if you do not intend to plot a complex value.
for ii = 2:6
set(P3,'Rdata',abs(SixPlots(1:ii)),'ThetaData',angle(SixPlots(1:ii)));
drawnow
end
As expected, P1 and P3 are both scalar PolarCompassPlot and P2 is a 1x6 vector of PolarCompassPlot(s)
P1,P2,P3
P1 =
PolarCompassPlot with properties: Color: [0.0660 0.4430 0.7450] LineStyle: '-' LineWidth: 0.5000 ThetaData: [0 1.0472 2.0944 3.1416 -2.0944 -1.0472] RData: [1 2.0000 3 4 5 6] Use GET to show all properties
P2 =
1×6 PolarCompassPlot array: PolarCompassPlot PolarCompassPlot PolarCompassPlot PolarCompassPlot PolarCompassPlot PolarCompassPlot
P3 =
PolarCompassPlot with properties: Color: [0.0660 0.4430 0.7450] LineStyle: '-' LineWidth: 0.5000 ThetaData: [0 1.0472 2.0944 3.1416 -2.0944 -1.0472] RData: [1 2.0000 3 4 5 6] Use GET to show all properties
Can I use compassplot then convert to a .PNG file then save the .PNG to an array?
Yes. Use getframe to record the axes or the figure, imwrite and then imread it from the file and store the result in an array. Or just getframe since that stores the results in an array directly.
Or use exportgraphics to save to a file and then imread() the file.
Caution: if you are thinking of animating the various files, then be careful, since getframe() and exportgraphics by default are not precisely consistent on the size of the captured image, so it is common to need to imresize to get exact consistency.
set(cp, 'DeleteFcn', '???')
I think the documentation says that this will stop the deletion. Correct?
What do I use for ???
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Animation en Centro de ayuda y File Exchange.

Productos

Versión

R2025b

Etiquetas

Preguntada:

el 19 de Dic. de 2025

Comentada:

el 22 de Dic. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by