我有一个Matlab脚本,我在其中生成一个图形,然后使用命令print('myFile','-depsc')在我的当前目录中创建一个eps文件。紧随其后的是: mypdf = eps2pdf('myFile')。
我得到的错误信息是‘创建临时eps文件时出错:.....无法访问或不存在’。
有没有人遇到过类似的问题?有什么建议吗,我可能做错了什么?我使用的是Ubuntu和Matlab2017a。
下面是我在命令行中键入的示例代码。我得到了我上面提到的错误消息。
figure()
plot(linspace(1,100),linspace(1,100)) %Simple line
print('my_plot','-depsc') %Create eps file.
mypdf = eps2pdf('my_plot'); %Should produce mypdf in my current directory.
<error message prints>
发布于 2018-06-10 05:26:55
这不是一个标准函数。如果你阅读这个函数,你会看到它为此返回的errStr。
function [ok,errStr] = read_epsfilecontent( epsFile )
% Reads the content of the eps file into epsFileContent
global epsFileContent
ok = 0;
errStr = [];
fh = fopen(epsFile,'r');
if fh == -1
errStr = ['File: ' epsFile ' cannot be accessed or does not exist'];
return
end
然后我们计算fopen返回-1的时间
fileID =fopen(文件名)打开文件filename进行二进制读取访问,并返回一个等于或大于3的整数文件标识符。MATLAB®保留文件标识符0、1和2分别用于标准输入、标准输出(屏幕)和标准错误。
如果fopen无法打开文件,则fileID为-1。
这意味着请发布您的一些代码,以便我们可以找出它无法打开您的文件的原因。
编辑:经过一些变通,没有必要下载代码,这就是我如何解决你的问题的。在运行您的代码时,有另一个名为eps2xxx的实现,我收到此错误
创建临时eps文件时出现
错误:*.eps -文件:无法访问C:\Users\Ryan\Documents\MATLAB*.eps或该文件不存在
这将我引向这里的文档中的信息。
% Create tmp file,...
[ok,errStr] = create_tmpepsfile(source,tmpFile,orientation);
if ~ok
status = ['Error while creating temporary eps file: ' epsFile ' - ' errStr];
if nargout, result = 1; end;
if nargout > 1, msg = status; else, disp(status); end;
我读到你需要GhostScript,我不确定我有没有这个。我下载了它,并给出了通向GS的完整路径,如下所示。
figure()
fullgspath = 'C:\Program Files\gs\gs9.23\bin\gswin64c.exe';
plot(linspace(1,100),linspace(1,100)); %Simple line
print('my_plot','-depsc');
eps2xxx('my_plot.eps',{'pdf'},fullgspath);
它在这里创建了你漂亮的小pdf。
https://stackoverflow.com/questions/50778613
复制相似问题