Main Content

select

Select subset of messages in rosbag

Description

bagsel = select(bag) returns a BagSelection object, bagsel, that contains all of the messages in the BagSelection object, bag.

This function creates a copy of the BagSelection object or returns a new BagSelection object that contains the specified message selection.

example

bagsel = select(bag,Name,Value) provides additional options specified by one or more name-value pair arguments. For example, "Topic","/odom" selects a subset of the messages, filtered by the topic /odom.

example

Examples

collapse all

Retrieve the rosbag. Specify the file path.

bag = rosbag('ex_multiple_topics.bag');

Use select with no selection criteria to create a copy of the rosbag.

bagCopy = select(bag);

Retrieve the rosbag. Specify the file path.

bag = rosbag('ex_multiple_topics.bag');

Select all messages within the first second of the rosbag.

bag = select(bag,'Time',[bag.StartTime,bag.StartTime + 1]);

Input Arguments

collapse all

Messages in a rosbag, specified as a BagSelection object.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: "Topic","/odom" selects a subset of the messages, filtered by the topic /odom.

ROS message type, specified as a string scalar, character vector, cell array of string scalars, or cell array of character vectors. Multiple message types can be specified with a cell array.

Example: select(bag,"MessageType",{"nav_msgs/Odometry","rosgraph_msgs/Clock"})

Data Types: char | string | cell

Start and end times of the rosbag selection, specified as an n-by-2 vector.

Example: select(bag,"Time",[bag.StartTime,bag.StartTime+1])

Data Types: double

ROS topic name, specified as a string scalar, character vector, cell array of string scalars, or cell array of character vectors. Multiple topic names can be specified with a cell array.

Example: select(bag,"Topic",{"/odom","/clock"})

Data Types: char | string | cell

Output Arguments

collapse all

Copy or subset of rosbag messages, returned as a BagSelection object.

Version History

Introduced in R2019b