How to place two .fig files together into one .fig file?

8 次查看(过去 30 天)
Just wonder something like this:
figureList = {'figure1.fig','figure2.fig'};
subplot(1,2,1)
plot(figureList{1});
subplot(1,2,2)
plot(figureList{2});
Is it possible?

回答(2 个)

Voss
Voss 2025-4-4
First, I create 2 figures and save them to .fig files, for demonstration:
f1 = figure();
plot(1:10)
legend()
f2 = figure();
plot(2:20,'r')
savefig(f1,'figure1.fig')
savefig(f2,'figure2.fig')
Now copy the current axes and any associated legend from each .fig file to subplots in a new figure:
figureList = {'figure1.fig','figure2.fig'};
N = numel(figureList);
newf = figure();
for ii = 1:N
oldf = openfig(figureList{ii},'invisible');
ax = oldf.CurrentAxes;
axl = copyobj([ax,ax.Legend],newf);
subplot(1,N,ii,axl(1),'Parent',newf)
delete(oldf)
end

Walter Roberson
Walter Roberson 2025-4-4
In the general case, you cannot merge two .fig files into one .fig file. .fig files are each a combination of graphics information and behaviour associated with the graphics, and although you can potentially merge the graphics information, you cannot generally merge the associated behaviour.
If you know that you do not have any associated behaviour, and you know that you do not have any special toolbar behaviour configured, then the general mechanism is
fig1 = openfig('FigFile1.fig', 'handlevisibility', 'on');
fig2 = openfig('FigFile1.fig', 'handlevisibility', 'on');
sfig1 = struct(fig1);
sfig2 = struct(fig2);
isuif1 = isfield(sfig1, 'isUIFigure');
isuif2 = isfield(sfig2, 'isUIFigure');
if isuif1 || isuif2
fig3 = uifigure();
else
fig3 = figure();
end
t1 = uipanel(fig3, 'Units', 'normalized', 'Position', [0 .5 1 0.5]);
t2 = uipanel(fig3, 'Units', 'normalized', 'Position', [0 0 1 0.5]);
copyobj(get(fig1, 'Children'), t1);
copyobj(get(fig2, 'Children'), t2);
delete(fig1);
delete(fig2);

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by