Function fileread reads some values wrong

I'm triying to read text from a file (extension .ubx, file attached ) into a matrix A . For this i'm using the follwing line of code
A = fileread([filepath filename]);
Basically this is working. But all characters with hex value 0x96 in the original file, matlab reads wrong value of hex 0xFF in matrix A.
This behavior occured with Matlab R2015a , R2015b , R2016a on Windows 10. But with Matlab R2015b and R2016a on Apple Macbook, everything works correctly.
To display matrix A in hex format, i use the command
format hex
uint8(A)
Does anybody know what i did wrong? I also tryed the command textread, but this gave the same result.

 Respuesta aceptada

Guillaume
Guillaume el 14 de Jul. de 2016
"all characters with hex value 0x96". As far as I can tell, these hex values are not characters in any standard text encoding. And that is your problem: you're attempting to read a file that is a combination of text and binary data as purely text. As a result, the binary portion gets munged when it is converted to text.
The solution is to read the file as binary and convert only those portions that are supposed to be text as text:
fid = fopen('08 mitte links.ubx');
binarycontent = fread(fid, '*uint8'); %read file as bytes (uint8)
text{1} = char(binarycontent(48:229)')

1 comentario

Mark Hruszczak
Mark Hruszczak el 16 de Jul. de 2016
Editada: Mark Hruszczak el 16 de Jul. de 2016
Thanks for your answer and your help! Now it works!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Preguntada:

el 14 de Jul. de 2016

Editada:

el 16 de Jul. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by