Avoid saving graphics in Matlab

Launching R2014b Matlab changed the way of saving variables using the command save

; Matlab also changed the way graphics descriptors are stored, they are now saved as structures. If you have graphic pens in the workspace, Matlab takes longer to save the file mat

, the math file size is large, and when you load the file, all the saved numbers have slipped out, which annoys me. It also issues 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 all graphics descriptors?

Please do not suggest that I can clearvars

draw shapes before saving them.

thank

+3


source to share


2 answers


You can get information about the current workspace variables by using whos

and save only those variables whose class is not a graphical descriptor 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


source


You can choose which variables you keep.

Example:



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

      

where var_name1

, etc. are the names of the variables you want to store.

0


source







All Articles