Parallel workers pop-up figures while executing scripts. Is it possible to have the figures created on background while still being able to save them as files?

14 views (last 30 days)
In MATLAB R2025b, when running in parallel mode (pool type Processes), figures created by workers pop up and steal focus from whatever application I’m using, while Matlab is running. In MATLAB R2024b, the same workflow does not cause the same problem, i.e. figures do not pop-up.
Below is all the code that I have tried to execute inside each worker's function but none have worked until now.
% Pool & Job submission
pool = gcp("nocreate");
if ~isempty(pool) && wf_new_parallel
delete(pool);
parpool(wf_parallel_type,nW);
elseif isempty(pool)
parpool(wf_parallel_type,nW);
end
p = gcp();
% Run once on every worker and WAIT for it
f = parfevalOnAll(p, @disable_worker_figures, 0);
wait(f);
% --- inside worker code (process_subject) ---
set(0, 'DefaultFigureVisible', 'off');
disp(['Figure visibility set to: ' get(groot,'DefaultFigureVisible')])
% --- helper you tested ---
function disable_worker_figures()
% Hide classic figures
set(groot,'DefaultFigureVisible','off');
% Hide UIFigures (if used)
try
set(groot,'DefaultUIFigureVisible','off');
catch
end
% Stronger: force invisibility at creation time
set(groot,'DefaultFigureCreateFcn', @(h,~) set(h,'Visible','off'));
try
set(groot,'DefaultUIFigureCreateFcn', @(h,~) set(h,'Visible','off'));
catch
end
% WindowStyle doesn't prevent focus stealing; keep normal
try
set(0,'DefaultFigureWindowStyle','normal');
catch
end
end

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2025b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!