reading from a binary file

2 Ansichten (letzte 30 Tage)
Doug
Doug am 25 Feb. 2011
I am getting an '18„N¦NÆN' instead of an '18' using fread. What is wrong here?
Thanks.

Antworten (1)

Jan
Jan am 25 Feb. 2011
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 Kommentare
Walter Roberson
Walter Roberson am 28 Feb. 2011
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 am 28 Feb. 2011
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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by