登录论坛

查看完整版本 : 如何在MATLAB中获取所有打开的图形的句柄


poster
2019-12-10, 20:48
我在matlab中有9个打开的图形(由另一个函数生成),我想将它们全部打印到文件中。有谁知道如何抓住MATLAB中所有打开的图形的句柄?

我知道gcf但是它似乎并没有满足我的要求。



回答:

有几种方法可以做到这一点。一种方法是获取根对象的 (https://www.mathworks.com/help/matlab/ref/groot.html)所有子对象 (https://www.mathworks.com/help/matlab/ref/groot.html) (在以前的版本中由句柄0 ):

figHandles = get(groot, 'Children'); % Since version R2014b figHandles = get(0, 'Children'); % Earlier versions 或者您可以使用功能findobj (https://www.mathworks.com/help/matlab/ref/findobj.html) :

figHandles = findobj('Type', 'figure'); 如果任何图都有隐藏的句柄 (https://www.mathworks.com/help/matlab/ref/figure-properties.html#property_d0e277247) ,则可以改用findall (https://www.mathworks.com/help/matlab/ref/findall.html)函数:

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

更多&回答... (https://stackoverflow.com/questions/4540604)