For MAT-files, -append adds new variables to the file or replaces the saved values of existing variables with values in the workspace.
换句话说,如果.mat文件中的变量称为A,则可以使用-append选项将该变量保存在A的新副本(您已设置为[])中)。在.mat文件中仍然会有一个名为A的变量,但它将为空,从而减少总文件大小。
以下是一个例子:
>> A = rand(1000); %# Create a 1000-by-1000 matrix of random values
>> save('savetest.mat','A'); %# Save A to a file
>> whos -file savetest.mat %# Look at the .mat file contents
Name Size Bytes Class Attributes
A 1000x1000 8000000 double
文件大小将约为7.21 MB。现在这样做:
>> A = []; %# Set the variable A to empty
>> save('savetest.mat','A','-append'); %# Overwrite A in the file
>> whos -file savetest.mat %# Look at the .mat file contents
Name Size Bytes Class Attributes
A 0x0 0 double
现在文件大小将在169字节左右。变量仍然在,但它是空的。