How to read long double?
13 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!