How to read each column of a .BIN file as a different variable
18 views (last 30 days)
Show older comments
Bradley
on 3 Dec 2024 at 22:01
Commented: Star Strider
ongeveer 10 uur ago
Hello,
I have an autonomous boat and it collects a lot of data. The data is stored in a .BIN file and when I open the .BIN file the files are not readable by humans. There is a program called ArduPilot Log Viewer that I can use to look at this data but thats time consuming and I dont want to run it everytime I run the boat. Im trying to plot various things like battery health, telemetry, speed etc. in ArduPilot Log Viewer I can open this file and export the things I want as a CSV, this is how I have been doing it up to this point. I dont know how many columns there are in this data, probably dozens of columns. To read the data im using the code below, but when I do this is put every data point in a single column, I dont know where the columns end. I only need 10 of the dozens of columns produced so most of the data is useless to me. The file size is 100-300mb each.
The code im using is:
fid = fopen("00000002.BIN");
data = fread(fid, '*int16');
fclose(fid);
Im still new to Matlab so I can try to answer any questions that might help. What I want it to open this file and create a new variable for each column of data. Thanks again!
0 Comments
Accepted Answer
Star Strider
on 3 Dec 2024 at 22:26
Edited: Star Strider
on 3 Dec 2024 at 22:27
I suggest using ‘ArduPilot Log Viewer’ once to see what the format of the file should look like (and check to be certain that the data are read correctly by fread). Once you know the format (and have verified that the data are read correctly), experiment with the reshape function to create the correct size matrix from the column vector. After that, use the array2table function to put it in a table, and then supply the correct variable names or each column.
EDIT — Corrected typographcial errors.
2 Comments
Star Strider
ongeveer 10 uur ago
As always, my pleasure!
I have no experince with ‘ArduPilot Log Viewer’, although some programs that are probably similar to it (for different products). One option is to e-mail the coompany, or visit the company’s equivalent of MATLAB Answers, to see if you can get any information there about the format. The options may also be encoded in the file itself, so that ‘ArduPilot Log Viewer’ can read and format it correctly. If so, that may make reading and formatting it in MATLAB easier.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!