copyobj to copy .fig from Figure window to Axes inside GUI

5 views (last 30 days)
Hello. This is my problem.
I have a GUI (one Figure) with several Tabs, and some of then have axes (mostly to plot a .jpg or a graph).
In one of this Tabs I have a button that has a callback which opens a new Window (Figure(2)), where it opens a .jpg and I draw some lines (imline) by hand, and then saves this Figure to a .fig file (using savefig). After that, i try to open the .fig file to one of the axes on the GUI.
In most of my attempts (using copyobj) i get the error "Axes cannot be a child of Axes". How can I solve this?
This is 'myhandles', which contains the handles of the GUI. The 'OWSO_main' is the Figure of the GUI, and 'W6_figure_tag' is the axes (inside a Tab) where i want to display the contents of the .fig file.
fig1.PNG
When i use Hfig = openfig('myfig.fig'), Hfig appears as a 1x1 Axes.
I have tried the approachs below, with no sucess.
I can provide more information if needed.
Thanks in advance.

Accepted Answer

Walter Roberson
Walter Roberson on 28 Aug 2019
figure() objects can never be the child of an axes()
uipanel() can never be the child of an axes()
axes() can never be the child of an axes()
There is no possibility that you will be able to copyobj() the figure or the axes into an axes.
The closest you can get is to copy the children of the original axes into the new axes.
  2 Comments
Mechrod
Mechrod on 28 Aug 2019
Thanks for the fast reply.
I think i understood what you said. Except:
"The closest you can get is to copy the children of the original axes into the new axes." . How can i do this? Do you have any suggestion?
Walter Roberson
Walter Roberson on 28 Aug 2019
axch = findall(OldAxes, 'depth', 1);
copyobj(axch, NewAxes)
It is tempting to instead use axch = children(OldAxes) but that will omit children whose handle visibility is not 'on'
Note that this will fail if you attempt to copy objects between the wrong kinds of axes. For example you cannot copy a polar() object to a regular axes. Also, you may need to take special steps if the old axes has datetime or duration axes .
Sometimes the easiest thing to do is not to copyobj, and to instead set the Parent property of OldAxes to the container of NewAxes (figure or uipanel) and then change the Units and Position properties to move it to the location inside the container that you want.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

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

Start Hunting!