使用 rosbag()函数加载bag文件
bag = rosbag('F:\2021-02-27-16-43-24.bag');
其中 ‘F:\2021-02-27-16-43-24.bag’ 是bag文件的存放位置。加载后的结果为:
使用select()函数选择需要的消息类型
msgs = select(bag,'MessageType','nav_msgs/Odometry');
使用readMessages() 函数读取数据
data = readMessages(msgs);
当存在同名的消息类型时,可以使用select() 函数先选择话题,再读取数据,其代码如下:
lidarpoint = select(bag,'Topic','/tb3_0/lidar_points');
msgStructs = readMessages(lidarpoint,'DataFormat','struct');
其中 'DataFormat','struct' 表示数据输出为struct形式。