You can use a 2-liner.
f = figure(1);
f.Visible = 'off';
Or, you could put it into a function so that you can use a 1-liner (that references a 2-lined function).
function h = invisibleFig(n)
h = figure(n);
h.Visible = 'off';
end
now create a new figure with
Alternatively, don't specify the figure number and use the figure handle instead. This is almost always the better approach.
h = figure('Visible','off');
Recap
Try each section below to become familiar with these methods. The key is to use the figure handle (h, in my lines below).
To create a figure,
To create an invisible figure,
h = figure('Visible','off');
To set the visibility on,
h.Visible = 'on';
set(h, 'Visible', 'on')
To make a figure current,
figure(h)
set(0,'CurrentFigure',h)
If you want to control the figure number and the visibility you must do that in two lines. However, it's rarely necessary to control the figure number. Use the figure handle instead.
h = figure(1);
h.Visible = 'off';
Lastly, and importantly, use the figure handle to specify a parent of an axes or any other object being added to the figure.
Example:
h = figure();
ax = axes(h);