Main Content

timeseries

Create time series object for selected message properties

Since R2019b

Description

example

[ts,cols] = timeseries(bag) creates a time series for all numeric and scalar message properties. The function evaluates each message in the current BagSelection or rosbagreader object bag as ts. The cols output argument stores property names as a cell array of character vectors.

The returned time series object is memory efficient because it stores only particular message properties instead of whole messages.

example

[ts,cols] = timeseries(bag,property) creates a time series for a specific message property, property. Property names can also be nested, for example, Pose.Pose.Position.X for the x-axis position of a robot.

example

[ts,cols] = timeseries(bag,property,...,propertyN) creates a time series for range-specific message properties. Each property is a different column in the time series object.

Examples

collapse all

Load the rosbag. Specify the file path.

bag = rosbag('ex_multiple_topics.bag');

Select a specific topic. Time series supports only single topics.

bagSelection = select(bag,'Topic','/odom');

Create a time series for the '/odom' topic.

ts = timeseries(bagSelection);

Load the rosbag. Specify the file path.

bag = rosbag('ex_multiple_topics.bag');

Select a specific topic. Time series support only single topics.

bagSelection = select(bag,'Topic','/odom');

Create a time series for the 'Pose.Pose.Position.X' property on the '/odom' topic.

ts = timeseries(bagSelection,'Pose.Pose.Position.X');

Load the rosbag. Specify the file path.

bag = rosbag('ex_multiple_topics.bag');

Select a specific topic. Time series support only single topics.

bagSelection = select(bag,'Topic','/odom');

Create a time series for all the angular 'Twist' properties on the '/odom' topic.

ts = timeseries(bagSelection,'Twist.Twist.Angular.X', ...
          'Twist.Twist.Angular.Y', 'Twist.Twist.Angular.Z');

Load a rosbag log file and parse out specific messages based on the selected criteria.

Create a rosbagreader object of all the messages in the rosbag log file.

bagMsgs = rosbagreader("ex_multiple_topics.bag")
bagMsgs = 
  rosbagreader with properties:

           FilePath: '/tmp/Bdoc24a_2528353_1173766/tp199fe096/ros-ex26633229/ex_multiple_topics.bag'
          StartTime: 201.3400
            EndTime: 321.3400
        NumMessages: 36963
    AvailableTopics: [4x3 table]
    AvailableFrames: {0x1 cell}
        MessageList: [36963x4 table]

Select a subset of the messages based on their timestamp and topic.

bagMsgs2 = select(bagMsgs,...
    Time=[bagMsgs.StartTime bagMsgs.StartTime + 1],...
    Topic='/odom')
bagMsgs2 = 
  rosbagreader with properties:

           FilePath: '/tmp/Bdoc24a_2528353_1173766/tp199fe096/ros-ex26633229/ex_multiple_topics.bag'
          StartTime: 201.3400
            EndTime: 202.3200
        NumMessages: 99
    AvailableTopics: [1x3 table]
    AvailableFrames: {0x1 cell}
        MessageList: [99x4 table]

Retrieve the messages in the selection as a cell array.

msgs = readMessages(bagMsgs2)
msgs=99×1 cell array
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
    {1x1 Odometry}
      ⋮

Return certain message properties as a time series.

ts = timeseries(bagMsgs2,...
    'Pose.Pose.Position.X', ...
    'Twist.Twist.Angular.Y')
  timeseries

  Timeseries contains duplicate times.

  Common Properties:
            Name: '/odom Properties'
            Time: [99x1 double]
        TimeInfo: tsdata.timemetadata
            Data: [99x2 double]
        DataInfo: tsdata.datametadata

Input Arguments

collapse all

Index of the messages in the rosbag, specified as a BagSelection or rosbagreader object. You can get a BagSelection object by calling rosbag.

Property names, specified as a string scalar or character vector. You can specify multiple properties. Each property name is a separate input and represents a different column in the time series object.

Output Arguments

collapse all

Time series, returned as a Time object handle.

List of property names, returned as a cell array of character vectors.

Version History

Introduced in R2019b