How to read each column of a .BIN file as a different variable

9 次查看(过去 30 天)
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!

采纳的回答

Star Strider
Star Strider 2024-12-3
编辑:Star Strider 2024-12-3
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 个评论
Bradley
Bradley 2024-12-4
I think this will work, thank you!
The problem im having is that I cant figure out how many columns I have and I cant figure out if its a int16 or int32 file. ArduPilot Log Viewer has preset data sets you can view. Theres like 300 options in that program, Im not sure if thats all of the data im collecting or just presets that will show 0 if I open them. Its an annoying program. Ill keep looking into it, thank you!
Star Strider
Star Strider 2024-12-4
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

标签

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by