Save Matlab workspace without saving or deleting figures

荒凉一梦 提交于 2019-12-13 13:55:47

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/38131166/save-matlab-workspace-without-saving-or-deleting-figures

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