MATLAB Answers

How to copy a plot from a figure window to a GUI

6 views (last 30 days)
Haitham on 12 Aug 2015
Commented: Haitham on 25 Aug 2015
I have a callback button that does some calculations and then shows 4 graphs in 4 windows. I would like to create a new GUI that gathering all these graphs into one window. In other word, I have two GUIs and I want to pass some graphs between them. How can I do that? Thanks.


Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 12 Aug 2015
If you want to have a duplicate in the second location, use copyobj(). If you want to move them to the new location, set() the Parent property of the axes. (Note: if you are using legend and you are using R2014a or earlier, then Legend generates an axes with a hidden handle, so be sure to use findall() of the axes not just findobj())


Show 1 older comment
Walter Roberson
Walter Roberson on 12 Aug 2015
move_from = handle of first figure
move_to = handle of second figure
axchild = findall(move_from, 'type', 'axes');
set(axchild, 'Parent', move_to);
If you created your GUI using GUIDE, then the function that is the GUI name returns the figure handle. For example,
fig2 = MySecondGUI(); %start second GUI, grab its handle
and then you would use fig2 as handle of second figure in the code above.
Haitham on 12 Aug 2015
I'm not sure if I get it right but I have tried this code: In the first GUI:
hfigure10 = get(figure(10));
hfigure20 = get(figure(20));
hfigure30 = get(figure(30));
hfigure40 = get(figure(40));
Then in the second GUI:
hfigure10 = getappdata(0,'hfigure10');
hfigure20 = getappdata(0,'hfigure20');
hfigure30 = getappdata(0,'hfigure30');
hfigure40 = getappdata(0,'hfigure40');
After running the code, all the axes were empty and the command window shows that there are no errors in the code!

Sign in to comment.

Translated by