Why do I receive errors when trying the print a figure using the "append" flag?

6 views (last 30 days)
I have much code that prints generated figures to Postscript files using the following syntax:
print('-dpsc2', '-painters', '-noui', '-append', filename);
However, when there is no file in the directory to append to with the same filename, I receive the following warning/error:
Warning: File not found or permission denied.
> In D:\Applications\MATLAB6p5p1\toolbox\matlab\general\@char\delete.m at line 35
In D:\Applications\MATLAB6p5p1\toolbox\matlab\graphics\private\render.m at line 110
In D:\Applications\MATLAB6p5p1\toolbox\matlab\graphics\print.m at line 238
??? Error using ==> print
Error using ==> print
Error using ==> d:/applications/matlab6p5p1/toolbox/matlab/graphics/private/render
Error using ==> hardcopy
Can not read PostScript file.
Using the print function with the "-append" option should create a new file if one does not exist, and operates correctly in this manner in MATLAB 5.3 (R11). Why does this occur?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This bug has been fixed for Release 14 SP1 (R14SP1). For previous releases, please read below for any possible workarounds:
This has been verified as a bug in MATLAB 6.0 (R12) through MATLAB 7.0 (R14) in the way that the PRINT function operates with the append option when there are other files of the desired filename on the MATLAB path, but there is no file of the desired filename in the directory in which the file is to be written.
Currently, to work around this issue, you can either remove or rename the files on the path which have the same filename as that desired for the figure being exported, or you can use a script similar to the following example to ensure that the append option is left off if there is another file of the same name on the path:
% String variable of filename
filename = 'sampleFile.ps';
% Cell array of strings returned from WHICH
onpath = which(filename,'-all');
% If the filename is found somewhere on the path
if ~isempty(onpath)
% If the filename is NOT found in the current directory
if isempty(dir(filename))
% Print without the append option
print('-dpsc2', '-painters', '-noui', filename);
else
% Print with the append option
print('-dpsc2', '-painters', '-noui', '-append', filename);
end
else
% Print without the append option
print('-dpsc2', '-painters', '-noui', filename);
end

More Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!