Figure not appearing with gcf - is visible

조회 수: 6 (최근 30일)
Andy
Andy 2016년 1월 7일
댓글: Walter Roberson 2016년 1월 7일
When I use the anovan function as per the example below a figure is created. I want to edit the name of this figure (by adding a suffix). If I then try to get the name of the figure (as per last line of code below), a new figure is created as if there are no figures in the workspace. I've looked through the figure properties and the figure is visible. Is there something I am missing?
y = [52.7 57.5 45.9 44.5 53.0 57.0 45.9 44.0]';
g1 = [1 2 1 2 1 2 1 2];
g2 = {'hi';'hi';'lo';'lo';'hi';'hi';'lo';'lo'};
g3 = {'may';'may';'may';'may';'june';'june';'june';'june'};
[p,t,stats] = anovan(y,{g1,g2,g3})
get(gcf,'Name') %does not work (creates new figure)
If I try a different function such as multcompare it now works.
multcompare(stats) %needs the stats variable created by anovan
get(gcf,'Name') %this works

채택된 답변

Andy
Andy 2016년 1월 7일
Ok, the handle appears to be hidden.
This thread got me on the right path
http://uk.mathworks.com/matlabcentral/newsreader/view_thread/313495
I found the handle by using the following:
findall(0,'Type','Figure','Name','N-way ANOVA','HandleVisibility','callback')
and was able to change the HandleVisibility to 'on' so additional plots using this function would not be picked up by the findall command
  댓글 수: 1
Walter Roberson
Walter Roberson 2016년 1월 7일
More complicated but more efficient would be
findall( allchild(0), 'depth', 0, 'Type','Figure','Name','N-way ANOVA','HandleVisibility','callback')
For R2014b or later, allchild(0) would be better as allchild(groot)
The allchild(0) finds all the direct children of the root even if they are hidden. Figures are alway direct children of the root so there is no need to look at a lower depth, so you can then filter by depth 0.
The version you wrote has the possibility of examining every graphics object at all the levels of hierarchy, which is unnecessary.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by