785 views (last 30 days)

MathWorks Support Team
on 8 Sep 2010

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.

su yung-chih
on 14 Aug 2017

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)

Sign in to comment.

Sign in to answer this question.

See Also

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/101806-how-can-i-insert-my-matlab-figure-fig-files-into-multiple-subplots#comment_190081

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/101806-how-can-i-insert-my-matlab-figure-fig-files-into-multiple-subplots#comment_190081

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/101806-how-can-i-insert-my-matlab-figure-fig-files-into-multiple-subplots#comment_600976

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/101806-how-can-i-insert-my-matlab-figure-fig-files-into-multiple-subplots#comment_600976

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/101806-how-can-i-insert-my-matlab-figure-fig-files-into-multiple-subplots#comment_810643

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/101806-how-can-i-insert-my-matlab-figure-fig-files-into-multiple-subplots#comment_810643

Sign in to comment.