Copy graphics from figure to UIAxes

18 visualizaciones (últimos 30 días)
Jason
Jason el 7 de Abr. de 2023
Editada: Jason el 7 de Abr. de 2023
Hello, I create a plot on a UIAxes with many plots and text objects. I wanted to be able to save them and later on add additional data so I have managed tconvert all the graphics objects on my UIAxes to a figure using the following:
ax=app.UIAxes;
xlab=ax.XLabel; ylab=ax.YLabel;
yl=ax.YLim;
h = findobj(ax,'Type','line');
h1 = findobj(ax,'Type','text');
h2=findobj(ax);
fig=figure;
set(gcf,'color',[0.25,0.25,0.25]);
ax = axes;
new_handle = copyobj(h,ax); new_handle = copyobj(h1,ax);
grid(ax,'on');
ax.YLim=yl;
ax.XLabel=xlab; ax.YLabel=ylab;
I am then able to save this fig.
However, after re-opening this saved fig and trying to get the graphics objects from the figure to the UIAxes is where I am struggling.
I have tried:
ax=app.UIAxes;
%Get directory where data is
try
[file,folder]=uigetfile({'*.fig'},'Open Fig file',app.startfolder);
app.startfolder=folder;
catch
[file,folder]=uigettfile({'*.fig'},'Open Fig file','C:\');
end
openpath=fullfile(folder,file);
h=openfig(openpath);
ax=axes(h);
drawnow;
%f=gcf
%copyobj(h.Children, app.UIAxes)
%newax = copyobj(h,ax);
newax = copyobj(ax,app.UIAxes); %from, to
But get the error:
Error using copyobj
Axes cannot be a child of UIAxes.

Respuesta aceptada

Jason
Jason el 7 de Abr. de 2023
Editada: Jason el 7 de Abr. de 2023
Done it, had to get the children of the axes on the figure!
h=openfig(openpath);
Ax=h.Children
g=Ax.Children
%ax=axes(h);
n=numel(g)
hold(ax,'on');
for i=1:n
T=g(i).Type
newax = copyobj(g(i),app.UIAxes);
end
drawnow;
But one last question, can I get the graphics objects from the saved .fig wihtout actually opening it? (and then having to close it)

Más respuestas (0)

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by