MATLAB: Am I unable to print to PDF format when MATLAB 6.0 or 6.1 (R12 or R12.1) is installed in a directory with a space in the name

directoryghostscriptMATLABnamepdfprintspace

I have installed MATLAB in a directory with a space in the name (like C:\Program Files\MATLAB). When I try to print a figure in pdf format:
print -dpdf test.pdf
I receive the following error:
??? Error using ==> print
Error using ==> C:\Program Files\MATLAB\toolbox\matlab\graphics\private\ghostscript
Problem calling GhostScript. System returned error:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Best Answer

This has been fixed in MATLAB 6.5 (R13).
For previous versions, you can work around the problem by changing lines 150-151 of $MATLAB\toolbox\graphics\private\ghostscript.m (where $MATLAB is the root MATLAB directory) from:
[s, r] = privdos( pj, [ 'echo quit | ' gsPath '\gs "@' rsp_file ...
'" "' pj.FileName '"' ] );
to
[s, r] = privdos( pj, [ 'echo quit | "' gsPath '\gs" "@' rsp_file ...
'" "' pj.FileName '"' ] );