ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How can I use bag file data in Matlab? [closed]

asked 2011-09-27 03:21:02 -0600

fresh_ros_user gravatar image

I have datas in bag file such as velocity and acceleration from the sensors. I want to read data with respect to time domain to make calculations in Matlab. How can I gain the data and use in Matlab? Thanks for your answers.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Procópio
close date 2017-07-27 01:19:39.377581

2 Answers

Sort by » oldest newest most voted

answered 2011-09-27 03:31:16 -0600

DimitriProsser gravatar image

If you play back the bag, you can use:

rostopic echo -p /topic_name

to display the data in a MatLab-friendly format. You can output this to a text file with:

rostopic echo -p /topic_name > data.txt

Or, you can even convert a topic directly to CSV with:

rostopic echo -b file.bag -p /topic

NOTE: This will only work with simple message types. LaserScans, PointClouds, arrays, etc won't work very well because the entire message is rendered to text.

The other option would be to use the rosbag API, located here to load the data into a C++ program and manipulate it that way.

edit flag offensive delete link more


Or use the python API along with to write out a .mat file.
Dan Lazewatsky gravatar image Dan Lazewatsky  ( 2011-09-27 04:38:37 -0600 )edit

Could you please show how to open that text file in Matlab? None of the tutorials helped me solve this

miloup gravatar image miloup  ( 2014-04-06 21:15:57 -0600 )edit

Load the file to matlab workspace using the txtdata=load('filepath/mytextfile.txt). numdata=str2double(txtdata.mytextfile). Sometimes this does not work right away. Find out what is the import using commands like ischar() or isobj() and google the corresponding command to swap it to numericals.

Brivate Bungo gravatar image Brivate Bungo  ( 2017-03-20 08:28:22 -0600 )edit

answered 2017-07-25 18:37:43 -0600

snehesh gravatar image

You can use rosbag and select function in Matlab to load bag files into Matlab.

edit flag offensive delete link more


This answer would be more helpful if you included information such as what function to use instead of just posting a link which can disappear at some point.

jayess gravatar image jayess  ( 2017-07-25 19:33:28 -0600 )edit

Question Tools



Asked: 2011-09-27 03:21:02 -0600

Seen: 11,798 times

Last updated: Jul 25 '17