How can I insert my MATLAB figure (.fig) files into multiple subplots?

209 vues (au cours des 30 derniers jours)
I have two MATLAB figure (.fig) files which I would like to insert into the subplots of a new figure.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 17 Fév 2021
Modifié(e) : MathWorks Support Team le 17 Fév 2021
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.
  1 commentaire
Eric Sargent
Eric Sargent le 9 Déc 2020
Starting in R2019b, you can use tiledlayout to manage these axes.
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;

Connectez-vous pour commenter.

Plus de réponses (1)

Eric Sargent
Eric Sargent le 9 Déc 2020
Starting in R2019b, you can use tiledlayout to manage these axes.
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 commentaires
Eric Sargent
Eric Sargent le 19 Jan 2022
Can you add some example code and/or screenshots, please? It's working with the examples I've been testing, so I'm curious to learn more about what's happening for you and Moritz.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Tags

Produits


Version

R2008a

Community Treasure Hunt

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

Start Hunting!

Translated by