MATLAB Answers

Create Figure Without Displaying it

1,798 views (last 30 days)
John F
John F on 11 Jul 2012
Commented: MA-Winlab on 24 Mar 2019
Hi,
I'd like to create a figure and save it in the background without displaying it.
I've heard of setting the "visibility" setting to "off", but the figure window still pops up.
I'd rather just have the figure be created and saved in its specified folder without having to see it.
Any way to do this?
Thanks,
JF

  0 Comments

Sign in to comment.

Answers (3)

Thomas
Thomas on 11 Jul 2012
Edited: Thomas on 11 Jul 2012
Something like this?
a=1:4;
f = figure('visible','off');
plot(a)
saveas(f,'newout','fig')
Now to reopen the figure
% to open the figure
openfig('newout.fig','new','visible')

  3 Comments

MA-Winlab
MA-Winlab on 24 Mar 2019
Why I am not able to juts click on the saved figure to open it? I was able to view the figure only by using openfig!
Walter Roberson
Walter Roberson on 24 Mar 2019
double-click on a .fig will open it.
Note: .fig that are created by GUIDE will not be able to run their GUI if you open them this way. To launch a GUIDE GUI, you need to execute the .m file.
MA-Winlab
MA-Winlab on 24 Mar 2019
I am double clicking on the .fig files but they do not open. Hence I am using the line provided by @Thomas to save the figures!

Sign in to comment.


Luffy
Luffy on 11 Jul 2012
Edited: Walter Roberson on 31 Oct 2016
If h = figure;set(h, 'Visible', 'off');
% do ur plotting here
saveas(h,'figure.png');
You will not see a figure popping up,but you can see h in workspace

  1 Comment

Blanca Larraga
Blanca Larraga on 4 Jun 2018
I still get the figure popping up. I have some subplots within my figure; could this be the reason why? How could I solve it?

Sign in to comment.


cmmv
cmmv on 13 Jun 2016
Edited: cmmv on 13 Jun 2016
What if we create mutiple figure handles first. Then, the current axis (gca) corresponds to the final handle created. Currently, i set the gca using figure(handle);
How then, do we maintain the visibility setting 'off' if needing to call the handles in any order for plotting.
EG:
h1 = figure('doublebuffer','off','Visible','Off');
h2 = figure('doublebuffer','off','Visible','Off'); %gca is now here
set(h1,'Units','pixels','Position',[1 1 850 375]);
figure(h1); %<--- this continues to make h1 "visible"
subplot(1,2,1);
plot(time, data);

  1 Comment

Bart Doekemeijer
Bart Doekemeijer on 31 Oct 2016
You will want to do:
set(0,'CurrentFigure',h1);

Sign in to comment.

Sign in to answer this question.