Figure not appearing with gcf - is visible

2 views (last 30 days)
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

Accepted Answer

Andy
Andy on 7 Jan 2016
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 Comment
Walter Roberson
Walter Roberson on 7 Jan 2016
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!