MATLAB: How to overlap plots from different scripts

graphplotscript

Hello MATLAB community!
I am trying to overlap two plots from two different scripts in order to illustrate the different best fit lines for the two plots. I am a fairly new MATLAB learner and am unsure how to go about doing this. I tried combining the two scripts into one and following the first plot with "hold on," but that didn't work.
Any suggestions? Perhaps I could save my plot from the first script and upload it into the second script.
Thanks!

Best Answer

Look up the documentation for copyobj.
Not only is a new figure generated with the code you shared but a very important error message is produced as well.
Error using copyobj
Figure parent must be the root.
What you want to do is copy the children of axis 1 to axis 2.
Assuming each figure has 1 and only 1 axis,
p1 = openfig("fig1.fig");
p2 = openfig("fig2.fig");
copyobj(get(gca(p1),'Children'), gca(p2));
% ----------1------------ ----2---
% 1: children of axis in figure p1
% 2: axis of figure p2
Related Question