Disallow MATLAB to take focus automatically

"Smart"/Silent Figure by Daniel Eaton.


You could do this by making the figure invisible (visible off) at creation, and only making it visible when you want to show it.

For example:

f = figure('Visible', 'off'); %create an invisible figure
plot(rand(1,15)); %plot some stuff to it.

saveas(f, 'test.png', 'png'); %write out the image as a png
close(f); %destroy the figure

Alternatively: set(f, 'Visible', 'on'); %display a previously invisible figure

Note, if you save the figure as a Matlab .fig file, it will also save the fact that it is invisible, which can be a bit confusing.