0

I'm trying to read a binary data file containing time-series data in Matlab.

Sample data: [23,-10,47,19,-417,-434,-1,29,11,22,23,6,18,13,-383]

Command: fopen(filename,'r','ieee-le');

When I read the data in int8 format and compared to the ground truth, I realized for abs(data)<128, the data is stored in 1 byte, and when abs(data)>128, the data is stored in 2 bytes. And data of either lengths are intermixed together. e.g. for the sample data above, the data I read in int8 would be

[23,-10,47,19,95,-2,78,-2,-1,29,11,22,23,6,18,13,-127,-2]

Without prior knowledge of the true data, I would not have known that I should interpret the two bytes (marked in bold) together as one data point.

The digits in the two-bytes data points can also occur in the one-byte data points, so there's no obvious rule I can separate the two.

Am I reading the data correctly and is there any info I could use to correctly read the data?

4
  • 1
    Firstly, Please provide details about how the data is stored in the file (share a snapshot of the file). The file data format will help us understand how to interpret the data. Secondly, is it possible to save data in CSV file, the comma will help identify individual entities in the file Commented Feb 7, 2024 at 11:05
  • If your data is separated by commas, yo can read each element separately and check if it would fit in int8 or int16 and then store them accordingly. Commented Feb 7, 2024 at 11:23
  • But matlab does not allow different data formats in one array. (like int8 and int16 in a single array. It is not supported) Commented Feb 7, 2024 at 11:24
  • 3
    Can you just read everything as an int16? How is the data being written such that it's dumping mixed types into your binary data file? It doesn't seem like any program could be expected to guess the per-element data type unless there's some sort of defined schema Commented Feb 7, 2024 at 12:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.