由于数据量大且频繁自动保存,我决定使用matfile对象将保存方法从标准save()函数更改为部分保存:
https://www.mathworks.com/help/matlab/ref/matfile.html
我做了这个更改,因为使用save()会覆盖所有内容,即使对结构进行了微小的更改,也会大大减慢程序的速度.但是我注意到每次调用时使用matfile保存的时间都会线性增加,经过一些调试后我注意到这是由于文件大小每次都在增加,即使数据被相同的数据覆盖也是如此.这是一个例子:
% Save MAT file with string variable and cell variable
stringvar = 'hello'
cellvar = {'world'}
save('test.mat', 'stringvar', 'cellvar', '-v7.3')
m = matfile('test.mat', 'Writable', true);
% Get number of bytes of MAT file
f = dir('test.mat'); f.bytes
% Output: 3928 - inital size
% Overwrite stringvar with same data.
m.stringvar = 'hello';
f = dir('test.mat'); f.bytes
% Output: 3928 - same as before
% Overwrite cellvar with same data.
m.cellvar = {'world'};
f = dir('test.mat'); f.bytes
% …Run Code Online (Sandbox Code Playgroud)