MATLAB: How to render and export many figures without the figures grabbing the window focus all the time

displayexportfigurefocusrendersteal focuswindow focus

I am rendering many figures in a sequence, and exporting them as images (I use export_fig, but could equally use saveas or print). While the program is running I'd like to be able to do other things on my computer, but the figure window keeps stealing the window focus, making this very difficult.
Any solutions?

Best Answer

The easiest option is to use the same figure window for each figure, and clear it before each new rendering. If you need to reset the current figure, use:
set(0, 'CurrentFigure', fh);
instead of:
figure(fh);
to avoid the focus being stolen.
In summary:
fh = figure;
for a = 1:num_figs
% Generate the data for rendering here
A = rand(10, 3);
% Select the figure and clear it
set(0, 'CurrentFigure', fh);
clf reset;
% Rendering code here
plot(A);
% Figure exporting code here (don't use saveas or getframe)
print(fh, '-depsc', sprintf('test%3.3d.eps', a));
end
Related Question