Getting figure and adding it to guide axes
1 view (last 30 days)
Show older comments
ricard molins
on 27 May 2015
Commented: ricard molins
on 27 May 2015
I have been given some code which generates a plot inside a figure when runned. I'm designing a GUI that should include this figure in the axis. The problem is that I'm able to get the handle of the figure the code generates but I'm not able to put it inside the axes from my guide. Right now I have this part of the code but I'm not able to make the final step to put h/figure(1) into the axes1.
code.run() %Generates figure(1)
h = code.getFigureHandle(); %I get the handle
axes(handles.axes1);
0 Comments
Accepted Answer
Walter Roberson
on 27 May 2015
No, that is not possible. A figure cannot be contained in any other object. Figures also always have children objects, some of which cannot be contained in an axes; for example in R2014a, if you
h = figure(1);
then even without drawing in it, it will have children of type uimenu, uipushtool, uitogglesplittool, uitoggletool, uitoolbar, none of which can be children of axes.
It is common for figures to have multiple axes; for example legend() creates additional axes.
For these reasons, you should not just arbitrarily move a figure or the contents of a figure into an axes.
What is usually reasonable to do is to create a uipanel, and to run through all of the non-ui* direct children of the figure and set() the Parent of the object to be the uipanel.
code.run() %Generates figure(1)
h = code.getFigureHandle(); %get the handle
panelh = handles.uipanel1; %presuming you already created it
hc = findall(h, '-depth', 1);
hct = get(hc,'type');
fighand = strcmp(hct, 'figure');
uihand = strncmp(hct, 'ui', 2);
hc(fighand | uihand) = []; %get rid of those
for ch = hc
try; set(ch,'Parent', panelh); catch; end
end
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!