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);
댓글 수: 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!