我能找到的RAM允许的最简单的方法是简单地重新声明它:
global A
A=3;
whos A
Name Size Bytes Class Attributes
A 1x1 8 double global
B=A;
whos B
Name Size Bytes Class Attributes
B 1x1 8 double % Note: not global
clear -global
A=B;
clear B;
whos A
Name Size Bytes Class Attributes
A 1x1 8 double
如果您更频繁地需要此变量,只需使用此变量删除global标志并再次保存。
在R2016b上使用save和load :
global exportmat
exportmat = cell(889,12);
filename = 'test.mat';
save(filename)
clear exportmat
load('test.mat')
% whos exportmat
exportmat2=exportmat;
whos
Name Size Bytes Class Attributes
exportmat 889x12 85344 cell global
exportmat2 889x12 85344 cell
filename 1x8 16 char
如果R2015a不适用于单元格(由于我没有该版本,我无法检查),您可以重新分配每个单元格内容,如果它们包含双精度数,则应该有效:
B = cell(size(A));
for ii = 1:size(B,1)
for jj = 1:size(B,2)
tmp = A{ii,jj};
B{ii,jj} = tmp;
end
end