MATLAB: Make saved figures visible on

figures visible save invisible loadMATLAB

I perform large batches of simulations, in which I generate a lot of figures and save them as fig. To avoid, that these figures pop up and make any further work on the machine impossible, I generate these plots in invisible figures. Then i save them as .fig files. This action conserves the property invisible, so that a loading of such a figure only leads to a visible figure, after doing a set(gcf,'visible','on')
I tried to set the state of the visibility in the file on the disk by using the following function:
function makevisible(file)
f=load(file,'-mat');
n=fieldnames(f);
f.(n{1}).properties.Visible='on'; % this line does not have much effect in 16b, used to be the key line in earlier versions.
f.(n{2}).GraphicsObjects.Format3Data.Visible='on';
save(file,'-struct','f')
end
sadly the command: f=load(file,'-mat'); does not only load the data into the workspace struct f, but also generates a figure. This figure then becomes visible, when changing the state. I tried to delete this figure with
close gcf
even before I set the visibility. But this does not only delete the figure, but also alters the data in f. after the close gcf command f is the struct of a "having been deleted figure".
How can I achieve to have saved figure files with visible on, without having every one of these figures to pop up on the screen. ???
My Solution
Its not exactly what I originally wanted, as it still saves the figures invisible. But it solves the described problem by defining a create function, which sets the visibility to on during creation.
function makevisible(file)
top =load(file,'-mat' ,'hgM_070000' );
top.hgM_070000.GraphicsObjects.Format3Data.CreateFcn = 'set(gcf,''visible'',''on'')'
save(file,'-struct','top','-append')
end

Best Answer

I repost here the solution, I posted myself in the comments before, in order to be able to "accept" an Anwer:
Its not exactly what I originally wanted, as it still saves the figures invisible. But it solves the described problem by defining a create function, which sets the visibility to on during creation. (Strangely, this procedure was not possible in R2012b where I tried this first. I guess it works since the large figure changes in R2014b(?) )
function makevisible(file)
top =load(file,'-mat' ,'hgM_070000' );
top.hgM_070000.GraphicsObjects.Format3Data.CreateFcn = 'set(gcf,''visible'',''on'')'
save(file,'-struct','top','-append')
end
This works, but I felt unconfortable about the strange hgM_070000 variable, which has to be used.
Adam then brought up the Idea to make this step directly in the saving application and not as a rework step after saving the file.
This is of course a good Idea. It makes the execution faster, and the fiddling around with this mysterious hgM_070000 Variable falls away.
ha.CreateFcn = 'set(gcf,''visible'',''on'')';
Jan still sees some difficulties in this Method, as gcf might be redefined in the matlab Workspace or path, where the figure is beeing opened.
True, but the unexperienced user will just doubleclick the fig file, and his (perhaps never before used) Matlab installation starts. Little chance of having redefined gcf. And the experienced user should know, that he should not do things like this, or he would know how to deal with the error message.