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!