How do i read binary file

14 ビュー (過去 30 日間)
Cristian Martin
Cristian Martin 2020 年 10 月 19 日
コメント済み: Cristian Martin 2020 年 10 月 20 日
Hi guys,
I have to read from a binary file and transform to decimal for example the first 8 groups at 8 bit level and the folowing 7 groups at 56 bit level as integer.
I tried this :
fileID = fopen('test.bin');
precision = '1*uint8';
B = fread(fileID,[1,1],precision);
%% I know this read only the first group and its mean 0 but for example I want to skip the first 8 groups and read after them the following 7 at 56 bit level
%% And after that I want to read specific groups at the same 56 bit level
%% I think I made my self clear otherwise please ask me if something that you dont understand.
Thanks!

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 19 日
Try this
fileID = fopen('test.bin');
precision = '1*uint8';
fseek(fileID, 8, 0); % skip 8 bytes
B = fread(fileID,[1,7],precision); % read 7 bytes
  11 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 10 月 20 日
I haven't experimented with reading the file, which is also being updated. You need to do some tests whether it works correctly and next fread() will read the new data correctly. For periodic execution of the code, check timers.
Cristian Martin
Cristian Martin 2020 年 10 月 20 日
It's working I already tried and it's OK, the result is updated every time I hit Run. But I guess I have Tu figure how is with the timers... Thanks...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by