How can I read a binary file with multiple word formats?

4 views (last 30 days)
So I'm working on a file that is a stream of 16-bit words that I need to extract data from. The first word is actually 32-bits (word 1 and word 2 concatenated together) followed by 3 more 16-bit words. This pattern repeats to the end of the file.
I currently have:
fidin = fopen('Filename.RAW','r');
time = fread(fidin,[1,inf],'bit32',6);
fseek(fidin,4,'bof');
words = fread(fidin,[3,inf],'bit16',4);
but it doesn't seem to be outputting the information in the style I'm looking for. I know what the data should look like because I have a separately created text file of the same data and it look nothing like it.
I figured I could read all the 16+16bit time words as one run of the file, then skip to 4 bytes into the file and read all of the 3x16-bit words as a second run. This does not seem to be the case.

Accepted Answer

Guillaume
Guillaume on 3 Nov 2014
Edited: Guillaume on 3 Nov 2014
As per the documentation of the skip parameter: If you specify a precision of bitn or ubitn, specify skip in bits.
Your skip argument is wrong! Either change the precision to 'int32' and 'int16' or the skip to 48 and 32 respectively.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!