Copying existing .fig files into Panel

6 次查看(过去 30 天)
I'd like to use Panel from the File Exchange instead of subplot so I can have more control over the margins between subplot figures. I have a number of existing Matlab .fig files I'd like to put in a grid.
However, when I use copyobj to copy the children from a .fig file into an existing panel ( p = panel() ), I get the resulting error:
fig1 = openfig(char('file.fig'), 'reuse');
>> copyobj(allchild(get(fig1, 'CurrentAxes')), p(1,1));
Error using copyobj
Line cannot be a child of panel.
This method also results in an error:
>> fig1 = get(fig1_gca, 'children');
>> copyobj(fig1, p(1, 1))
Error using copyobj
Axes cannot be a child of panel.
Is there a better way to open existing .fig files and copy them into Panel?

回答(1 个)

Max Murphy
Max Murphy 2019-11-11
Sorry if this answer is too late to help you, but it looks like in your examples above you were trying to copy children of an axes object into a panel. In your first example, you could copy the axes (fig1_gca, from second example) into the panel p(1,1), or you could create a new axes in p(1,1) and copy the children of fig1_gca into that axes.
I had a similar question and this was my solution:
oldFigFiles = {'oldFig1.fig'; 'oldFig2.fig'};
nOldFig = numel(oldFigFiles);
newFig = figure('Name','oldFig contents in tabs');
tg = uitabgroup(newFig);
t = gobjects(nOldFig,1);
p = gobjects(nOldFig,1);
for i = 1:nOldFig
oldFig = openfig(oldFigFiles{i});
c = get(oldFig,'Children');
% Move contents of oldFig into current tab
t(i) = uitab(tg,'Title',oldFigFiles{i});
p(i) = uipanel(t(i));
copyobj(c,p(i));
delete(oldFig); % close old figure
end

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by