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?
댓글 수: 0
답변 (2개)
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
댓글 수: 0
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


