Hello Francis,
You were on the right track, but you only made one subplot. I'm assuming, since you're using subplot, that you want two separate axes on the figure. Here's a quick example of how you can do it with copyobj:
hFig1 = figure;
plot(1:10)
hold on
plot(2:20)
hFig2 = figure;
plot(10:-1:1)
hold on
plot(1:10)
hFigTarget = figure;
hAxTar1 = subplot(2, 1, 1, 'Parent', hFigTarget);
hAxTar2 = subplot(2, 1, 2, 'Parent', hFigTarget);
hAx1 = hFig1.Children;
hAx2 = hFig2.Children;
copyobj(hAx1.Children, hAxTar1)
copyobj(hAx2.Children, hAxTar2)
Another way to do it would be to just copy over both axes, and change their 'Position' or 'OuterPosition' properties to simulate what subplot does. I personally find that this works pretty well to simulate subplots:
hAx1.Units = 'normalized';
hAx1.OuterPosition = [0 0.5 1 0.5];
hAx2.Units = 'normalized';
hAx2.OuterPosition = [0 0 1 0.5];
-Cam
Best Answer