problem with print - "file name contains characters that are not contained in the filesystem encoding"

2 views (last 30 days)
The operation
>> file = 'C:\Users\fbo\Documents\test.png';
>> print(file);
leads to
Error using fopen The file name contains characters that are not contained in the filesystem
encoding. Certain operations may not work as expected.
Error in name (line 84)
fidread = fopen(pj.FileName,'r');
Error in print (line 197)
pj = name( pj );
Error in print
Howeverer, the command
>> file = 'test.png';
>> print(file)
works fine.
Searching the web for a solution resulted in the command
>> restoredefaultpath
and I was then able to execute the print command. But the restoredefaultpath command also removed a lot of useful paths that are no longer available.
So, how can I keep all my paths and have the print command working?
Cheers,
Fredrik

Answers (1)

Steven Lord
Steven Lord on 16 Sep 2015
The fact that RESTOREDEFAULTPATH resolved the issue makes me suspect that you have an FOPEN on one of those "useful paths" that is shadowing the FOPEN function included with MATLAB. What does this command show?
which -all fopen
You should see the built-in FOPEN function, a serial method, and possibly (depending what toolboxes you have installed) an icinterface method and an i2c method. If you see something else that is NOT part of a MathWorks product listed, try removing the directory containing that file from the MATLAB path and try printing again.
Alternately if you want to see for certain which FOPEN is being used, set a breakpoint in the private helper function name using this command, then try to PRINT again:
dbstop in private/name at 84
When you reach that breakpoint, execute:
dbstep in
If I'm correct in my suspicion, it will go into the FOPEN that's shadowing the built-in version.
Once you've finished debugging, clear all the breakpoints using this command, so you don't have to go past that breakpoint every time you call PRINT later in that session of MATLAB:
dbclear all
  2 Comments
Fredrik
Fredrik on 17 Sep 2015
Thank you for your reply. I'm not sure what to make of the outcome of your advice, so I will present the output and maybe you can give me a new recommendation.
which -all fopen
built-in (C:\Program Files\MATLAB\R2015b\toolbox\matlab\iofun\fopen)
C:\Program Files\MATLAB\R2015b\toolbox\matlab\iofun\@serial\fopen.m % Shadowed serial method
C:\Program Files\MATLAB\R2015b\toolbox\shared\instrument\@icinterface\fopen.m % Shadowed icinterface method
dbstop in private/name at 84
print(file)
dbstep in
This make the onCleanup class to pop up on line 60 (the line "h.task();" below:
function delete(h)
% DELETE - Delete a ONCLEANUP object.
% DELETE does not need to be called directly, as it is called when the
% ONCLEANUP object is cleared. DELETE is implicitly called for all ONCLEANUP
% objects that are local variables in a function that terminates.
%
% See also: CLEAR, ONCLEANUP, ONCLEANUP/ONCLEANUP
h.task();
end

Sign in to comment.

Categories

Find more on Search Path in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!