How to read different bits from a binary file?

13 views (last 30 days)
Hi. I am trying to read a binary file with MATLAB which contains different bits (8-bits and12-bits).
I read stream 1 easily with ('*uint8'). But can you help me to read stream 2 and 3 from the binary file, please?

Accepted Answer

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 27 Nov 2020
Just employ: 'unit16' instead of 'uint8'.

More Answers (1)

Walter Roberson
Walter Roberson on 28 Nov 2020
Edited: Walter Roberson on 28 Nov 2020
I could read stream 1 (8-bits) with a command of "stream1 = fread(fileID, 113:3600112 '*uint8')".
No, do not do that. Instead fseek forward by 112 bytes from the beginning of the file, and fread with size 3600000 with *uint8.
For the second group you do not need to move after the first group. fread 3600000 elements using 'ubit12=>uint16'
For the third group you do not need to move after reading the second group. Do the same fread 3600000 'ubit12=>uint16'
I was concerned because the majority of time that data structures are spoken about as 12 bit, really what is meant is using 16 bits per sample with either the 4 MSB or LSB unused. However the sizes work out perfectly for it to really be 12 bits per sample.
  3 Comments
Eliza
Eliza on 29 Nov 2020
Thanks a lot. Your answer was so helpful.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!