4
votes

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

2
see also stackoverflow.com/questions/38131166 for similar answerCarl Witthoft

2 Answers

4
votes

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{:});
0
votes

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.