Close all figures which are not docked
3 次查看(过去 30 天)
显示 更早的评论
Is there any easy way to close all figures which are not docked? Either a high level command or a way to loop over figures and check if it is docked and close it iff it is not.
0 个评论
采纳的回答
Constantino Carlos Reyes-Aldasoro
2019-11-25
When figures are docked, the position always start in the origin (i.e. 1,1), you could detect this location by using gcf like this:
>> get(gcf,'Position')
ans =
1 1 623 237
In contrast, when you open a figure, it will not be in the origin:
>> get(gcf,'Position')
ans =
560 528 560 420
Thus, if you loop through your figures and check the origin, you can select those which have 1,1 and close those ones, and leave the other ones open (or vice versa).
2 个评论
Rik
2019-11-25
Some methods of maximizing figures use a similar method, so this check is not fool-proof.
更多回答(1 个)
Rik
2019-11-25
Using the script below I generate the list of properties that are different between docked and undocked figures. After running this, the variable s_diff contains the comparison. Using this I found the WindowState property, which was already present in relatively old releases ( doclink to R2012b ). So you can use this property to find and close all undocked figures:
function close_all_undocked
figHandles = findobj('Type','Figure','-not','WindowStyle','docked');
close(figHandles,'Force')
end
Although in this case it would have been faster to search the documentation for useful properties, this shows the method for when that fails.
try close(1),catch,end
try close(2),catch,end
f1=figure(1);clf(1)
f2=figure(2);clf(2)
uiwait(msgbox('dock one figure and hit ok to continue'))
s1=struct(f1);
s2=struct(f2);
drawnow
clc % clear the warning about unhiding implementation details
fn1=fieldnames(s1);
fn2=fieldnames(s2);
if ~isequal(fn1,fn2)
error('fields don''t match!')
end
s_diff=struct;
for n=1:numel(fn1)
if ~isequal(s1.(fn1{n}),s2.(fn1{n}))
s_diff(1).(fn1{n})=s1.(fn1{n});
s_diff(2).(fn1{n})=s2.(fn1{n});
end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!