A colleague has a MATLAB startup.m
file that contains interactive code (it calls the command questdlg
to ask him which project directory he wishes to work in).
This works fine for him when running MATLAB directly. However, he also needs to run MATLAB code in parallel, having started up a matlabpool
.
When starting up, the workers in the matlabpool
are running his startup.m
file, getting to the questdlg
and then hanging (infinitely, or until Ctrl C).
An easy solution is to just get rid of the interactive code from his startup.m
, as it's not really essential.
But is there a way to detect whether this startup.m
is being run by a worker starting up - something similar to isdeployed
or ismcc
? Then he could keep the interactive code that he finds useful, but only execute it when not starting up a worker.
The command getCurrentWorker
seemed like it might be what was needed, but I believe that only works during the execution of a task, rather than at startup.
You could use the usejava
function to see if the interactive desktop is running, which is probably a good enough approximation unless you frequently use -nodesktop
mode.
if usejava('desktop')
questdlg(...);
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With