Is it possible to display multiple figures next to each other

10 views (last 30 days)
I'm doing a project where it's usefull for me to compare figures and view them alone.
I was wondering wether it's possible to first generate the figures seperately and later in the code display them next to each other without having to recalculate everything.
I've found 2 different ways that I could do this, and written a small code to show how.
e.g. 1.
(This is the first way I'd do this)
y = [1 2 3 4 5 6];
x1 = 5*y;
figure()
plot(x1,y)
x2 = y.^2;
figure()
plot(x2,y)
figure()
tiledlayout(2,1)
ax1 = nexttile;
plot(x1,y)
ax2 = nexttile;
plot(x2,y)
e.g. 2.
(This is the second way I've found to do this)
y = [1 2 3 4 5 6];
x1 = 5*y;
figure()
plot(x1,y)
x2 = y.^2;
figure()
plot(x2,y)
figure()
plot(x1,y)
hold on
plot(x2,y)
hold off
Both of the above mentioned methods work, but for figures that take more time to generate, it's quite stupid to generate them twice, so I'm hoping that one of you can give me a faster way to plot at least one of the 2 above mentioned methods.

Accepted Answer

Mehmed Saad
Mehmed Saad on 4 May 2020
You can use copy object
close all
y = [1 2 3 4 5 6];
x1 = 5*y;
figure()
a1=plot(x1,y);
x2 = y.^2;
figure()
a2=plot(x2,y,'r');
%
figure()
f=gca;
copyobj([a1 a2],f)

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!