How to read long double?

13 次查看(过去 30 天)
Andrew
Andrew 2012-12-24
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

回答(1 个)

José-Luis
José-Luis 2012-12-24
编辑:José-Luis 2012-12-25
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.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by