Binary file reading.
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pappu Murthy
el 11 de Sept. de 2018
Comentada: Greg
el 14 de Sept. de 2018
I have a binary file data which I am trying to read. the first data of record is 8 integer numbers. They are precision "int" which means each number is 4 byte long. so I use A = fread(fid,[1 8],'int') it showas numbers A(2) thru A(8) correctly... but number A(1) is some strange number. Also the last number is missing. If I do A = fread(fid, [1,9],'int') and take the numbers A(2) thru A(9) I am able to read all my numbers correctly. SO my question is why the very first number is some unwanted stuff and needs to be skipped to read correctly.
0 comentarios
Respuesta aceptada
Greg
el 11 de Sept. de 2018
Editada: Greg
el 11 de Sept. de 2018
Nobody can possibly answer your question: "why... unwanted stuff...?" Only the author of the binary file format can tell you that. --More specifically, those 4 bytes actually exist in the file. MATLAB isn't misbehaving in any way.
I can tell you that you've already solved your problem. Simply skip 4 bytes and proceed. I bet they are useful somehow, but not likely as an int32. Try other 4-byte formats like float32, or 4*char. Maybe it's a float32 datestamp?
9 comentarios
Greg
el 14 de Sept. de 2018
FYI, frewind is redundant immediately after fopen.
Further, fseek is better than reading and trashing unwanted bytes. For a single value it won't make much difference in speed, but the code is cleaner.
*Accidentally posted as answer. Moved to comment *
Más respuestas (0)
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!