0
votes

I have a Matlab script where I produce a figure, and then create an eps file in my current directory using the command print('myFile','-depsc'). Immediately following, I have: mypdf = eps2pdf('myFile').

I get the error message that 'Error while creating temporary eps file: ..... cannot be accessed or does not exist'.

Has anyone had a similar problem? Any suggestions what I might be doing wrong? I'm using Ubuntu and Matlab 2017a.


Here is an example code that I type into the command line. I get the error message which I stated above.


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>

1
Please add some more code as per my comments. - user1911226
Step 1: do you have a file called “myFile” in the current directory? Are you sure it’s not “myFile.eps”? - Cris Luengo
In my current directory: myFile.eps - D.B.
Did you try eps2pdf('myFile.eps') instead of eps2pdf('myFile')? - Cris Luengo

1 Answers

1
votes

This isn't a standard function. If you read the function you will see errStr that it returns for this.

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

Then we figure out when fopen returns -1

fileID = fopen(filename) opens the file, filename, for binary read access, and returns an integer file identifier equal to or greater than 3. MATLAB® reserves file identifiers 0, 1, and 2 for standard input, standard output (the screen), and standard error, respectively.

If fopen cannot open the file, then fileID is -1.

Which means please post some of your code so we can figure out why it cannot open your file.

Edit: After some work around and it wasn't necessary to download the code this is how I solved your problem. There is another implementation called eps2xxx While running your code I received this error

Error while creating temporary eps file: *.eps - File: C:\Users\Ryan\Documents\MATLAB*.eps cannot be accessed or does not exist

Which lead me to the information in the documentation here.

% 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;

And I read you needed GhostScript, I wasn't sure if I had this anyways. I downloaded it and gave the full pathway to GS like the following.

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);

which created your nice little pdf here.enter image description here