Read double precision numbers from binary file
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Franck D'Araujo
el 4 de Mzo. de 2015
Comentada: Franck D'Araujo
el 5 de Mzo. de 2015
Hello,
I have to read double precision numbers from a binary file. I'm used to do that in C, which basically looks like that for a LSB first coded file :
char *cAddress = NULL;
double value = 0;
cAddress = (char*)(value);
*cAddress = ucBuffer[uiOffset];
*(cAddress + 1) = ucBuffer[uiOffset + 1];
*(cAddress + 2) = ucBuffer[uiOffset + 2];
*(cAddress + 3) = ucBuffer[uiOffset + 3];
*(cAddress + 4) = ucBuffer[uiOffset + 4];
*(cAddress + 5) = ucBuffer[uiOffset + 5];
*(cAddress + 6) = ucBuffer[uiOffset + 6];
*(cAddress + 7) = ucBuffer[uiOffset + 7];
Now, I would like to implement that in Matlab. Do you have any idea on how I should proceed ?
Thanks a lot for supporting
Franck
0 comentarios
Respuesta aceptada
James Tursa
el 4 de Mzo. de 2015
Editada: James Tursa
el 4 de Mzo. de 2015
Did you mean to type the following:
cAddress = (char*)(&value); // Added the & for type punning
Otherwise, the method of getting the bytes into the double isn't apparent. In any event, you should be able to simply use fopen with the proper machinefmt option, followed by fread with the '*double' option. Are doubles the only thing(s) in the file?
3 comentarios
James Tursa
el 4 de Mzo. de 2015
... the code most likely crashes."
I don't even think it will compile. I would be surprised if a compiler let you convert a double value directly into a pointer.
Ver también
Categorías
Más información sobre Low-Level File I/O 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!