4

我正在使用 matlab 将数字编写为 eps 文件以在 LaTeX 中使用,使用:

print( '-depsc', 'filename.eps');

我将这些 eps 文件保存在版本控制中。由于我一次生成了很多数字,但只更改了其中的一两个,因此特定 eps 文件中的唯一更改通常是:

-%%CreationDate: 06/29/2011  17:52:57
+%%CreationDate: 06/30/2011  19:18:03

这不是有价值的信息。有没有办法阻止 matlab 编写 CreationDate?

鼓励肮脏的解决方案...

4

1 回答 1

4

一种解决方案是完全删除该行,并依靠文件系统来跟踪创建/修改日期。这可以使用常见的 shell 工具以多种方式完成:

# sed
sed -i file.eps '/^%%CreationDate: /d'

或者

# grep
grep -v '^%%CreationDate: ' file.eps > tmp && mv tmp file.eps

如果您在 Windows 机器上,MATLAB 应该包含一个 Perl 解释器:

# perl
perl -i -ne 'print if not /^%%CreationDate: /' file.eps

在 MATLAB 中,您可以执行以下操作来调用单行 Perl 程序:

%# construct command, arguments and input filename (with quotes to escape spaces)
cmd = ['"' fullfile(matlabroot, 'sys\perl\win32\bin\perl.exe') '"'];
args = ' -i.bak -ne "print if not /^%%CreationDate: /" ';
fname = ['"' fullfile(pwd,'file.eps') '"'];

%# execute command
system([cmd args fname])
于 2011-06-30T12:55:04.297 回答