67

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.

4

4 回答 4

82

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
于 2010-12-27T17:51:57.270 回答
18

最好的事情之一是不需要寻找把手。创建每个图形时,请捕获其句柄。

h(1) = figure;
h(2) = figure;
...

正如这里的一位开发人员告诉我的那样:

它们被称为把手,因为你应该抓住它们

于 2010-12-27T18:00:00.513 回答
12

我认为findall应该工作

handles=findall(0,'type','figure')

于 2010-12-27T17:54:09.850 回答
7

您已经为手柄质量得到了很好的答案。但是原始问题的另一个提示-打印所有要归档的图形:您可以使用publish选项,而无需处理图形或句柄。

于 2013-11-19T23:31:58.437 回答