我有一些数据 (.mat) 在保存时设置为全局,现在保存为全局单元格。当我将它加载到工作区时,它会自动设置为全局。
有没有办法从这个变量中删除全局标志,而不从工作区中删除变量本身,只从全局属性中删除?
当我复制这个数组时,它也会自动复制它的全局属性,并且在 documentation 中它只说明如何设置为全局而不是如何删除它。我正在使用 MATLAB R2015a。
global exportmat
exportmat = cell(889,12);
filename = 'test.mat';
save(filename)
clear -globals exportmat
load('test.mat')
whos
Name Size Bytes Class Attributes
exportmat 889x12 85344 cell global
最佳答案
在 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 上使用保存
和加载
:
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 不适用于单元格(我无法检查,因为我没有那个版本),您可以重新分配每个单元格内容,如果它们包含 double ,这应该可以工作:
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
关于matlab - 如何从工作区中的变量中删除全局标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50366294/