Avoid saving of graphics in Matlab

五迷三道 提交于 2019-12-10 20:58:45

问题


Starting R2014b Matlab has changed the way how variables are saved using save command; Matlab has also changed the way graphic handles are saved, they are saved as structures now. If you have graphic handles in workspace Matlab takes it longer to save the mat file, size of mat file is large and when you load the file all the saved figures are popped-up, which is irritating to me. It also produces a warning:

Warning: Figure is saved in Oakley_19_PDEparameterEstimation.mat. Saving graphics handle variables can cause the creation
of very large files. To save graphics figures, use savefig. 

I have a simple and straightforward question:

How can I avoid saving of all graphic handles?

Please do not suggest that I can clearvars figure handles before saving them.

Thanks


回答1:


You can get information about the current workspace variables using whos and save only those variables whose class is not a graphics handle object (i.e. the class name string does not include 'matlab.graphics' or 'matlab.ui'):

varData = whos;
saveIndex = cellfun(@isempty, regexp({varData.class}, 'matlab.(graphics|ui)'));
saveVars = {varData(saveIndex).name};
save('no_handles.mat', saveVars{:});



回答2:


You can select which variables you save.

Example:

save('data.mat', 'var_name1', 'var_name2', 'var_name3');

where var_name1 etc... are the names of the variables you want to save.



来源:https://stackoverflow.com/questions/45560181/avoid-saving-of-graphics-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!