MATLAB: Arrange figures in numerical order…

sort figures

There's a nice little function on the exchange that sorts figures on the screen, but it's not sorting in numerical order how the Figures are numbed: https://www.mathworks.com/matlabcentral/fileexchange/52774-arrangefigures-handles
This statement I believe…
figureHandles = sort(get(0, 'Children'));
…needs to truly sort in Figure numerical order. Then it would work.
Can it be improved?
Thanks!

Best Answer

For HG2, it would be
figureHandles = handle( sort( double(findall(0, 'type', 'figure') ) );
This will find all figures, including the interface frames for apps; if you want only user created figures then change findall to findobj .
This code will sort according to numeric handle. Even in HG2, each graphics object is associated with a double, just like in HG1. And just like in HG1, the handles for figures are not necessarily integers. You cannot generally predict the range of double that will be associated with a figure that was not created with 'IntegerHandle', 'on' or by using figure(INTEGER) to create a figure with that particular integer handle.