I should be using something like this instead (thanks Zebb):
try
fh = fopen([p.Results.filename,'.eps'],'w');
fwrite(fh,epsfile);
fclose(fh);
catch %#ok -- this is required for r2007a support
err = lasterror; %#ok
if fh > 0
fclose(fh);
end
rethrow( err );
end
I should be using something like this instead (thanks Zebb):