MATLAB: Use fread to read a binary file with multiple data sizes

binary datafread

I'm trying to read a binary data file that has 4 data points that have 8, 8, 16, and 32 bits of information. Is there a way to read this with fread or another function? I don't know how the file was created but the documentation states this is the file format. Thanks

Best Answer

Guessing at the representation:
d1 = fread(fid, 1, '*uint8');
d2 = fread(fid, 1, '*uint8');
d3 = fread(fid, 1, '*uint16');
d4 = fread(fid, 1, '*uint32');
This is not certain, as there can be differences in byte ordering, and differences in signed vs unsigned. Also we could reasonably speculate that the 32 bit piece of information might perhaps represent a single-precision floating point number instead of an integer.
Related Question