The documentation for the save
command says that you should delete figures if you don't want to bog down the *.mat
file. I save
to a *.mat
file periodically, and I re-use my figure after issuing clf
. I would prefer not to have to delete it just to save
a *.mat
file, then open a new figure. Is there a way to do this?
You can either save the variables you want explicitly when calling save
if you know all the variables you'd like to save.
save('output.mat', 'variable1', 'variable2', 'variable3');
Alternately, if you want to save all variables in your workspace that aren't graphics handles, something like this could work:
% Get a list of all variables
allvars = whos;
% Identify the variables that ARE NOT graphics handles. This uses a regular
% expression on the class of each variable to check if it's a graphics object
tosave = cellfun(@isempty, regexp({allvars.class}, '^matlab\.(ui|graphics)\.'));
% Pass these variable names to save
save('output.mat', allvars(tosave).name)
This will not save any figures (or any graphics objects) and also will allow you to keep them open.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With