reading from a binary file

2 次查看(过去 30 天)
Doug
Doug 2011-2-25
I am getting an '18„N¦NÆN' instead of an '18' using fread. What is wrong here?
Thanks.

回答(1 个)

Jan
Jan 2011-2-25
The command, you did not show, is wrong. This might be better:
A = fopen(FID, [1, 2], 'char=>char')
But this is a bold guess only. If you show the necessary details of your FREAD command and the corresponding data, a useful help is more likely and less random.
  10 个评论
Walter Roberson
Walter Roberson 2011-2-28
The data that the OP read in at first appears to me to potentially be UTF-8 encoded, based upon the characters that the OP shows. I am concerned that if the OP continues to work with this data stream that the OP might encounter cases where the difference between reading "char" and "uint8" might become important. It would be safer for the OP to use uint8=>char if reading bytes if the OP's intent.
Jan
Jan 2011-2-28
No. If the OP reads a Unicode file, he will most likely open it in the necessary encoding scheme. If he then switchs from the working "fread(fid, 2, '*char')" to "fread(fid, 2, 'uint8=>char')" he will get a different unwanted result.
Now you found a point, were we two disagree. But who cares?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by