Copy graphics from figure to UIAxes

14 ビュー (過去 30 日間)
Jason
Jason 2023 年 4 月 7 日
編集済み: Jason 2023 年 4 月 7 日
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.

採用された回答

Jason
Jason 2023 年 4 月 7 日
編集済み: Jason 2023 年 4 月 7 日
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)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by