Getting figure and adding it to guide axes
2 次查看(过去 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);
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!