Reading file in binary format (double 64 pecision)

5 ビュー (過去 30 日間)
Said Rahal
Said Rahal 2017 年 1 月 12 日
回答済み: Walter Roberson 2017 年 1 月 16 日
I am trying to read a binary file (the attached one) with double 64 precision. Basically it is 64*1024 long, and contains intensity values (non-negative). I know I should use fread as such:
fid = fopen('sample_1_trace')
input1 = fread(fid,'double');
However, in the results obtained I am getting negative values. Can you please confirm whether I am reading the file the right way? Because if that is the case, the error may be in the file itself.
Note: I tried to attached the file, but I could not due to format restriction.
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 1 月 16 日
You can zip the file and attach that.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2017 年 1 月 16 日
Try
fid = fopen('sample_1_trace', 'ieee-be')

その他の回答 (1 件)

Wilson A N
Wilson A N 2017 年 1 月 16 日
I tried writing a binary file with both negative and positive values. Then I tried reading the binary file using fread just as you have mentioned. I got the values correctly as I have written to the binary file.

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by