How to read long double?

조회 수: 15 (최근 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