How to read binary data using matlab.
11 views (last 30 days)
Show older comments
I have a 55.4 GB binary data with a file name hab.bin. Its corresponding mettadata file contains the following information.
Start Time: 03/25/17 - 07:04:24:972357994
Channels: 8
TX Sample Rate: 13000000 Hz
TX Center Frequency: 49900000 Hz
RX Sample Rate: 200000 Hz
RX Center Frequency: 49900000 Hz
Baud Width: 20 usec
Inter-pulse Period: 5 msec
Number of Baud: 13
Phase Code: 1,-1,1,-1,1,1,-1,-1,1,1,1,1,1
Phase Increments:
Increment: 0 deg, Pulses: 100
Sampling Period: 5 usec
Num Sampling Periods: 300
Front Porch Time: 15 usec
Back Porch Time: 30 usec
To say something about the data: it is obtained from coherent backscatter radar with operating parameters given above in the metadata file. I tried to read the data in the command window and results in
>> fid=fopen('hab.bin');
>> a=fread(fid)
a =
[]
>> a=fopen(fid)
a =
/home/virtual/Desktop/data/hab.bin
>>
As you can see the final result is only the path of my binay data, hab.bin. Any help please?
2 Comments
Answers (1)
Image Analyst
on 26 Apr 2017
Use more input arguments for fread(). For example, here is a snippet from my code where I read the header of a binary file into a structure called stHeader:
% Read in the dimensions for the different directions.
% They'll be in bytes 9-20.
stHeader.x_size = fread(fileHandleID, 1, '*int32');
stHeader.y_size = fread(fileHandleID, 1, '*int32');
stHeader.z_size = fread(fileHandleID, 1, '*int32');
stHeader.TotalVoxels = stHeader.x_size * stHeader.y_size * stHeader.z_size;
% Read in the position of the center of the first pixel.
% They'll be in bytes 21-32.
stHeader.XStart = fread(fileHandleID, 1, '*float');
stHeader.YStart = fread(fileHandleID, 1, '*float');
stHeader.ZStart = fread(fileHandleID, 1, '*float');
Note the second and third arguments I used with fread().
2 Comments
Image Analyst
on 26 Apr 2017
Nonetheless, that's the way to do it. You have to know the format, like how many bits there are for each attribute, what data type they are, and what order they're in.
fread(fileHandleID, 1, '*int32') should return something so I'm surprised that you say it's empty. Even if it's being interpreted wrong or pointing to the wrong location, it should return 4 bytes, not an empty array. Perhaps if you attach hab.bin and your format (bytes, order, and class) we can see what we can do.
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!