matlabmatlab-figurematlab-hg2

What's the complete structure of a figure handle object?


Mathworks has done it again: my ancient R2012 (as bestowed by my company) returns a nice set of doubles identifying the figure window numbers in response to

currhandles=findall(0,'type','figure');

Now I got a fellow remotely IM-ing me 'cause the code I gave him fails under R2015 because findall now returns a structure for the figure handle. I can't play w/ his system (no RDC) and the mathworks documentation pages don't appear to specify the elements of the figure handle structure. In particular, I'd like to know if I can still retrieve the figure window number. Anyone know?


Solution

  • Of course.

    currhandles(:).Number
    

    will return all numbers as a comma-separated list.

    Or specify a number you want:

    currhandles(1).Number
    

    The order appears to be the inverse order of initialization.


    Alternatively you can define two anonymous functions to get an array directly:

    figure(1); figure(2); figure(42);
    
    getNumbers = @(x) [x.Number];
    getFigureNumbers = @() getNumbers([findall(0,'type','figure')]);
    
    getFigureNumbers()
    

    ans =
    
        42     2     1