Skip to content

Extract data from *.bag file to import in matlab

Jenn edited this page Oct 4, 2018 · 1 revision

In a terminal:

rostopic echo -b file.bag -p /topic > data.txt

This saves the data stored in a topic to a text file.

If you open the text file, you will see a header that contains the information of which column contains what data.

In matlab,

fid = fopen('data.txt');
data = textscan(fid, '%s%s%s%s', 'delimiter', ',' 'headerLines', 1);
fclose(fid);

The data is in a cell array.

The '%s%s%s%s' is just an example of a format spec (check here for more info).