How to read long double?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello community,
I need to read long double (C++) from binary file in matlab. Unfortunetly, long double has 10 bytes order (80 bites). How can I do that? Any idea?
Thanks in advance.
Andrew
0 comentarios
Respuestas (1)
José-Luis
el 24 de Dic. de 2012
Editada: José-Luis
el 25 de Dic. de 2012
I think the long double type is dependent on the architecture. If you wanted a really robust routine, you could read bit by bit and then transform your data, assuming you know the layout of long double.
doc fread
A short example:
fid = fopen('your_file.bin','r');
A = fread(fid, number_of_values * 2, 'ubit40'); %If your type is 80 bits long
fclose(fid);
Then you would need to reshape A, and find out the double values from the bits. All this might be pointless though, as I think Matlab does not support long doubles natively, so that precision might go to waste. You might be better off typecasting to double in your C++ code before importing to Matlab.
Then again, someone here might correct me.
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!