How can I insert my MATLAB figure (.fig) files into multiple subplots?
495 ビュー (過去 30 日間)
表示 古いコメント
MathWorks Support Team
2010 年 9 月 8 日
コメント済み: Eric Sargent
2022 年 5 月 10 日
I have two MATLAB figure (.fig) files which I would like to insert into the subplots of a new figure.
採用された回答
MathWorks Support Team
2021 年 2 月 17 日
編集済み: MathWorks Support Team
2021 年 2 月 17 日
In order to copy MATLAB figure (.fig) files into multiple subplots use the following commands:
h1 = openfig('test1.fig','reuse'); % open figure
ax1 = gca; % get handle to axes of figure
h2 = openfig('test2.fig','reuse');
ax2 = gca;
% test1.fig and test2.fig are the names of the figure files which you would % like to copy into multiple subplots
h3 = figure; %create new figure
s1 = subplot(2,1,1); %create and get handle to the subplot axes
s2 = subplot(2,1,2);
fig1 = get(ax1,'children'); %get handle to all the children in the figure
fig2 = get(ax2,'children');
copyobj(fig1,s1); %copy children to new parent axes i.e. the subplot axes
copyobj(fig2,s2);
For additional information on the COPYOBJ function, refer to the following documentation:
Attached are 2 scripts which will demonstrate how to place multiple FIG files into different subplots.
The file 'savfigs.m' creates 2 figures and saves them into the current working directory. Please run this file first.
The file 'copyaxes.m' opens these figures and then copies them to the different subplot axes.
4 件のコメント
Eric Sargent
2020 年 12 月 9 日
openfig('fig1.fig');
ax1=gca;
openfig('fig2.fig')
ax2=gca;
figure;
tcl=tiledlayout(1,2);
ax1.Parent=tcl;
ax1.Layout.Tile=1;
ax2.Parent=tcl;
ax2.Layout.Tile=2;
その他の回答 (2 件)
Eric Sargent
2020 年 12 月 9 日
openfig('fig1.fig');
ax1=gca;
openfig('fig2.fig')
ax2=gca;
figure;
tcl=tiledlayout(1,2);
ax1.Parent=tcl;
ax1.Layout.Tile=1;
ax2.Parent=tcl;
ax2.Layout.Tile=2;
su yung-chih
2017 年 8 月 14 日
For some reason, MATLAB may not be able to show the figure in short time. So, user had better add some time-delay after "ax = gac", or the subplot may repeat the same result.
if true
% code
end
ax = gca; pause(2)
0 件のコメント
参考
カテゴリ
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!