make saved figures visible on
25 次查看(过去 30 天)
显示 更早的评论
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
8 个评论
Jan
2016-12-17
编辑:Jan
2016-12-17
Creating callbacks as strings remains dangerous: As soon as a customer has redefined "gcf" in the command window, opening you fig files will produce strange and confusing results.
In older Matlab versions LOAD of a fig file did not open the figure. That this is the case now is rather confusing and impractical.
采纳的回答
Heinz
2016-12-19
2 个评论
Adam
2016-12-19
You can be a little more robust by using gcbo rather than gcf as this is explicitly the handle to the object whose callback is currently executing rather than just the current figure. This function handle approach for the CreateFcn appears to work after a quick test:
@(src,evt)set(gcbo,'visible','on')
Lucademicus
2019-10-23
Awesome solution Adam, thank you, this works like a charm on R2018b and R2019a.
更多回答(2 个)
Jan
2016-12-16
Are you really sure, that f=load(file,'-mat') opens the figure? This would be very strange.
Is it required to set "f.(n{2}).GraphicsObjects.Format3Data.Visible='on'"? Which Matlab version are you using?
A simply solution would to insert the code to enable the visibility during the loading of the figure.
2 个评论
Jan
2016-12-16
When loading the figure file as a struct opens the figure already, this figure must contain any code, which triggers the displaying. What a pitty. This seems to be a perfect example for the bad idea to mix code and data. Blame Mathworks.
Then you could go the hard way: Create the figures invisible at first. Then open all fig files, set the visibility and save the fig fiels again. Although this pollutes your screen, it will do this for a short period of time only.
In older Matlab versions the conversion from a figure to code worked: http://www.mathworks.com/matlabcentral/fileexchange/20152-guidegetter . I'm not sure, if this could be useful for your case.
Steven Lord
2016-12-16
Would using a command to open the figure that forces it to be visible satisfy your needs? If so use the openfig function with the 'visible' value for the visibility input argument as per the second example on that documentation page.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!