www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/BagSelectionExample.m
%% Create |rosbag| Selection Using |BagSelection| Object % Create a |BagSelection| object from a |rosbag| log file and parse out % specific messages based on the selected criteria. % Copyright 2015 The MathWorks, Inc. %% % Set the path to the logfile filepath = fullfile(fileparts(which('ROSWorkingWithRosbagsExample')), 'data', 'ex_multiple_topics.bag'); %% % Create a |BagSelection| object of all the messages in the log file. bagMsgs = robotics.ros.Bag.parse(filepath); %% % Select a subset of the messages based on their timestamp and topic. bagMsgs2 = select(bagMsgs, 'Time', ... [bagMsgs.StartTime bagMsgs.StartTime + 1], 'Topic', '/odom'); %% % Retrieve the messages in the selection as a cell array. msgs = readMessages(bagMsgs2); %% % Return certain message properties as a time series. ts = timeseries(bagMsgs2, 'Pose.Pose.Position.X', ... 'Twist.Twist.Angular.Y');