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

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?

Respuestas (2)

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
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);

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Productos

Versión

R2024b

Preguntada:

el 4 de Abr. de 2025

Respondida:

el 4 de Abr. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by