Retrospectively add graphs to tiled layout

For example, if I have 10 figures saved as .fig files in a directory and load them in via a script so i have figure 1, figure 2 etc., is there a way that I could put these figures in a tiledlayout(5,2) format even though the figures have already being produced beforehand?

 Accepted Answer

Yes, change the Parent property of each of your plot axes from their initial figure window to the tiledlayout.
plot(rand(1,5),'x-'); savefig('FIG1'); close %Make some fig files
plot(rand(1,10),'o-'); savefig('FIG2'); close
close all
f1=figure;
t=tiledlayout(1,2,'Parent',f1); %Create tiled layout
openTL('FIG1.fig',t,1); %Open .fig files and transfer the plots to the tiledlayout
openTL('FIG2.fig',t,2);
function openTL(file,t,i)
Hfig=figure(openfig(file));
axis equal
ax=findobj(Hfig,'Type','axes');
ax.Parent=t;
ax.Layout.Tile=i;
close(Hfig);
end

4 Comments

I don't think I understand. How would I do this, could you explain how you'd do it with the exmaple below?
x = linspace(0,10,100);
y=x;
figure(1);
plot(x,y);
y=x.^2;
figure(2);
plot(x,y);
From this stage do I need to go onto figure (1) and go to Edit -> axes properties and from here what do I do? What do I need to do with figure (2) to get it alongside figure(1)?
I've added an example.
Yes that worked great thanks Matt!

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!