Inhibit Matlab Window Focus Stealing

Nordlöw picture Nordlöw · Dec 13, 2011 · Viewed 11.1k times · Source

Is there a way to tell Matlab not to steal window focus (from an external editor) such as Emacs) upon graphical commands such as figure and plot. This would increase my productivity a lot because I often want to continue code development during data (re-)processing.

Answer

PearsonArtPhoto picture PearsonArtPhoto · Dec 13, 2011

It is possible, the trick is to not use the figure statement, but to change the current figure directly. This will change the active plot without changing the focus. Typically I do something like this:

function change_current_figure(h)
set(0,'CurrentFigure',h)

Then, all of the figure(h) statements need to be changed to change_curent_figure(h).

Note, this is included in the matlab documentation.

It should be noted, this only works if the figure is already created. If new figures are going to be periodically created, one could create the figures as the very first few lines of code, save the handles, do the processing, and then plot to them. This example would work. Note, the drawnow command will flush the event buffer, making sure all figures are plotted.

I've seen this work from 2007-2010, not sure if the latest or earlier versions support this, although I have no reason to suspect they don't.

fig1=figure;
fig2=figure;
drawnow;
[a b]=do_complex_processing;
change_current_figure(fig1)
plot(a);
change_current_figure(fig2)
plot(b);