matlabmatlab-figurefigures

How do I get the handles of all open figures in MATLAB


I have nine open figures in matlab (generated by another function) and I want to print them all to file. Does anyone know how to grab the handles of all open figures in MATLAB?

I know about gcf but it doesn't seem to do what I want.


Solution

  • There are a few ways to do this. One way to do this is to get all the children of the root object (represented in prior versions by the handle 0):

    figHandles = get(groot, 'Children');  % Since version R2014b
    figHandles = get(0, 'Children');      % Earlier versions
    

    Or you could use the function findobj:

    figHandles = findobj('Type', 'figure');
    

    If any of the figures have hidden handles, you can instead use the function findall:

    figHandles = findall(groot, 'Type', 'figure');  % Since version R2014b
    figHandles = findall(0, 'Type', 'figure');      % Earlier versions