Minimizing MATLAB windows while running?
조회 수: 10 (최근 30일)
이전 댓글 표시
In my code, series of images are being processed and at each stage I have to show different figures in several windows, but as you know while running each window comes up and prevents you from doing your other things with your PC while running.
Is it possible to ask MATLAB to minimize all the windows (while running), so that the user can do his other things meanwhile?
Thanks so much.
Steven
댓글 수: 0
채택된 답변
Image Analyst
2013년 12월 27일
Here's the official Mathworks word on that: http://www.mathworks.com/matlabcentral/answers/110789-how-do-i-create-a-figure-without-bringing-the-figure-window-to-the-front-in-matlab-r2013b
추가 답변 (1개)
DGM
2024년 7월 23일
이동: Adam Danz
2024년 7월 29일 15:43
I don't know why that reference answer got deleted, but it's still archived:
The issue here is that the creation of new figure windows will typically steal focus from other applications, depending on window manager settings. Minimizing windows afterward does nothing to solve the problem.
This is the original answer --->
A change was made in MATLAB R2013b that causes new figure windows to appear in the foreground. There are three workarounds to achieve the desired effect:
1. Make plots invisible as they are plotted, and return them to visible once all plots are complete.
There are two ways to make the plots invisible:
a) After each "figure" statement, execute:
set(gcf, 'visible', 'off');
b) Set the default figure visible option to 'off' once in the beginning:
set(0, 'DefaultFigureVisible', 'off');
Once all the plots are complete, return the property to 'on':
set(0, 'DefaultFigureVisible', 'on');
At the end of the script, make all the plots visible. Suppose there are n figures with numbers 1 through n. Execute:
set(1:n, 'visible', 'on');
2. Dock all new figures with
set(0, 'DefaultFigureWindowStyle', 'docked');
Return this property to normal at the end of the script with
set(0, 'DefaultFigureWindowStyle', 'normal');
3. Generate the n empty figures at the beginning of the script:
for i = 1:n
figure(i);
end
Then, when plotting, instead of "figure(i)", use
set(0, 'CurrentFigure', i);
If it is important to periodically check the outputs of the plots while the script is running, options 2 or 3 may be more useful than 1.
댓글 수: 1
Adam Danz
2024년 7월 29일 16:03
I like using docked figures to solve this issue. But there's an efficiency benefit to using visible='off'. Which ever one is used, I would specify the property value during figure creation and store the figure handles. I would also use onCleanup to turn visibility back on. The benefit is that if the code stops execution due to an unexpected error, the visibility will be turned on so you know the figures are there.
n = 4; % for 12 figures
figs = gobjects(n,1); % preallocate graphics array to store fig handles
for i = 1:n
figs(i) = figure('Visible','off');
end
turnOnFigVisibility = onCleanup(@()set(figs,'Visible','on')); % turn on visibility at end
% [YOUR OTHER GRAPHICS CODE]
% Turn on visibility at the end
% This line is not needed if this is within a function
clear turnOnFigVisibility
If figures aren't being created in a loop, this line turns on visibility for all existing figures.
figure('Visibile','off')
% [plotting stuff]
figure('Visibile','off')
% [plotting stuff]
turnOnFigVisibility = onCleanup(@()set(findall(groot,'type','figure'),'Visible','on')); % turn on visibility at end
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!