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

조회 수: 1 (최근 30일)
pietro
pietro 2016년 5월 6일
댓글: Walter Roberson 2016년 5월 9일
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]);
Txt=fscanf(TxtFid,'%c');
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?
Thanks
Cheers
  댓글 수: 3
pietro
pietro 2016년 5월 9일
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');
Walter Roberson
Walter Roberson 2016년 5월 9일
You need to provide valid entries there. Empty entries are not accepted.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2016년 5월 6일
Use fread() instead.
  댓글 수: 1
pietro
pietro 2016년 5월 9일
It worked. I just used fread in the following way:
Txt=fread(TxtFid);
Txt=char(Txt)';
Why is there so much difference among the two uses?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by