Figure not appearing with gcf - is visible

1 次查看(过去 30 天)
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 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by