Read a binary file with many type of data (Int64-int​32-int64-i​nt32....)

18 次查看(过去 30 天)
Hi,
i have a binary file generated by a DAQ equipment
This file contains header + data
this is the structure of the Header
64 bit 32 bit 64 bit 32 bit 32 bit 32 bit
The data is structured : Ch1 Ch2 Ch3 Ch4 Ch5 Ch6 Ch7 Ch8 Ch1 Ch2 Ch3 Ch4 Ch5 Ch6 Ch7 Ch8 Ch1 Ch2 Ch3 Ch4 Ch5 Ch6 Ch7 Ch8 ......
The type of data is int32
sampling rate depends of the configuration in my case is : 4Khz.
any idea ?
i have to read it bit by bit ?

回答(1 个)

Walter Roberson
Walter Roberson 2023-9-11
fid = fopen('filename');
H1 = fread(fid, 1, '*uint64');
H2 = fread(fid, 1, '*uint32');
H3 = fread(fid, 1, '*uint64');
H4 = fread(fid, 3, '*uint32');
data = fread(fid, [8 inf], 'int32') .';
fclose(fid);
You might need to adjust the datatypes of the header items.
You might need to use swapbytes
  3 个评论
Walter Roberson
Walter Roberson 2023-9-11
fid = fopen('filename', 'r', 'ieee-be'); %big endian
header.firstDate_s = fread(fid, 1, '*uint64');
header.firstDate_ns = fread(fid, 1, '*int32');
header.secondDate_s = fread(fid, 1, '*uint64');
header.secondDate_ns = fread(fid, 1, '*int32');
header.maskVoi = fread(fid, 1, '*int32');
header.size = fread(fid, 1, '*int32');
data = fread(fid, [8 inf], 'int32') .';
fclose(fid);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Standard File Formats 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by