Automatically Copy Legends from multiple UIAxes into Figure (in order to save that figure)

5 次查看(过去 30 天)
Hi!
I created an app, that consists of multiple Tabs, with multiple sub-Tabs each.
Every one of those sub-Tabs displays a couple of UIAxes. There is one save button on each Sub-Tab, that copies the UIAxes into a new figure and places a couple other objects into that figure (for example annotations).
My Problem is, that with copyobj, the legends do not get copied.
Is there a swift way of getting the legends into the new figure easily, without manually redoing all of them?
Code example of how the elements are created:
% Example of how a UIAxes is created in the app (Only the legend part is interesting i guess):
plot(app.UIAxes_S3_lu,fs,real(H4),fs,imag(H4));
axis(app.UIAxes_S3_lu,[0 30 -10 10]);
legend(app.UIAxes_S3_lu,'Realteil','Imaginärteil','NorthEast');
%
stem(app.UIAxes_S3_ru,fs,abs(H4));
hold(app.UIAxes_S3_ru,'on');
stem(app.UIAxes_S3_ru,fh,abs(H4h),'r');
axis(app.UIAxes_S3_ru,[0 30 0 10]);
legend(app.UIAxes_S3_ru,'Original','höhere Auflösung','NorthEast');%%
hold(app.UIAxes_S3_ru,'off');
%
% How the save Button is generally coded:
newfigure = figure('Position',[0.1*app.ss(3), 0.1*app.ss(4), 0.75*app.ss(3), 0.75*app.ss(4)]);
%
copyobj(app.UIAxes_S3_lu, newfigure);
copyobj(app.UIAxes_S3_ru, newfigure);
annotation (newfigure,'Example')
% etc
savefig(newfigure,'C:\User...');
delete(newfigure);
  3 个评论
Adam Danz
Adam Danz 2021-2-5
copyobj is the way to go as of r2020b but is not supported prior to that (or 2020a, I forget).
Note that copyUIAxes() from the file exchange also copies UIAxes and their legends (and colorbars) to another figure from Matlab r2016a to the current release (currently r2020b).

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by