# How to set parent figure of subplot which is not the current figure?

94 views (last 30 days)

Show older comments

Good evening, I plotted some graphs in several different figures. After that I want to add subfigures to an existing figure which is not the current figure any more. It should be something like this:

hfig1 = figure;

subplot(1, 2, 1);

plot(1, 1);

subplot(1, 2, 2);

plot(1, 1);

hfig2 = figure;

plot(1, 1);

ha1 = findobj(hfig1, 'Type', 'axes');

axis(ha1);

hs = subplot(2, 1, 2); % changed the last number from 1 to 2

spy

Unfortunately, spy is being plotted in the second figure instead of the first one. I do not want to define all subfigures at the beginning. Any suggestions are appreciated ...

##### 0 Comments

### Answers (2)

nl2605
on 8 May 2014

Well, what you can do is something like this:

hfig1 = figure;

subplot(1, 2, 1,'Tag','axes1');

plot(1, 1);

subplot(1, 2, 2,'Tag','axes2');

plot(1, 1);

hfig2 = figure;

plot(1, 1);

figure(hfig1);

ha1 = findobj(hfig1, 'Type', 'axes','-and','Tag','axes1');

axis(ha1);

spy

Hope that's what you wanted!

Image Analyst
on 9 May 2014

### See Also

### Community Treasure Hunt

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

Start Hunting!