Search code examples
matlabmatlab-figure

Disallow MATLAB to take focus automatically


I have the following problem: in my MATLAB code I use statements like

figure(1)

to change destination figure for some data. The problem is that after this MATLAB take system focus on the window with this figure.

When I run a big script in the background and try to do something else on my computer, MATLAB always takes focus and I can't do something normally.

Is there a way to disallow MATLAB to do this? I'm working in Linux Ubuntu.


Solution

  • In R2018a, the figure property "WindowState" was introduced, see https://blogs.mathworks.com/pick/2018/07/13/maximize-your-figures/

    Using this, you can do

    set(0, 'DefaultFigureWindowState', 'minimized');
    

    before running the actual script, and this will cause all "standard plots" to not steal focus and be opened in minimized state.

    There are functions that still steal focus. I did not investigate in detail, but I believe it's mainly automatic plotting functions such as psd, hist etc. without output arguments. If you call plot yourself you should be fine.