MATLAB Answers


Why fscanf return strange character I do not see in notepad?

Asked by pietro
on 6 May 2016
Latest activity Commented on by Walter Roberson
on 9 May 2016
Hi all,
I have several txt files that look fine in Notepad, but they are full of strange characters from fscanf and I'm wondering why it occurs.
Here my code:
TxtFid=fopen([TxtPath TxtFile]);
Here how the a part of the file looks like in notepad:
25,33 de / from 0 à / to 28,6
Here how the same part looks from fscanf:
≤ 25,33 de / from 0 à / to 28,6
Why does it occur? For the coding? May trying several codings solve the problem?
I tried yo change the coding as the following:
TxtFid=fopen([TxtPath TxtFile],[],[],'windows-847');
but Matlab returns:
Error using fopen
Invalid permission.
How may I solve the problem?


The permissions cannot be [], but at least 'r'.
From Matlab documentation:
fileID = fopen(filename,permission,machinefmt,encodingIn)
For this reason, I used the function as the following:
TxtFid=fopen([TxtPath TxtFile],[],[],'windows-847');
You need to provide valid entries there. Empty entries are not accepted.

Sign in to comment.



1 Answer

Answer by Image Analyst
on 6 May 2016
 Accepted Answer

Use fread() instead.

  1 Comment

It worked. I just used fread in the following way:
Why is there so much difference among the two uses?

Sign in to comment.