Getting figure and adding it to guide axes

4 次查看(过去 30 天)
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);

采纳的回答

Walter Roberson
Walter Roberson 2015-5-27
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
  1 个评论
ricard molins
ricard molins 2015-5-27
I got the idea of why my way was not working. Thanks for the code as I wouldn't have been able to do it without your help.
Worked like a charm

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by