www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/ReturnROSMessagesAsACellArrayExample.m

    %% Return ROS Messages as a Cell Array

%%
% Set file path.
filePath = fullfile(fileparts(which('ROSWorkingWithRosbagsExample')), 'data', 'ex_multiple_topics.bag');

%%
% Read rosbag and filter by topic and time.
bagselect = rosbag(filePath);
bagselect2 = select(bagselect, 'Time', ...
[bagselect.StartTime bagselect.StartTime + 1], 'Topic', '/odom');
%%
% Return All Messages as a Cell Array
allMsgs = readMessages(bagselect2);

%%
% Return The First 10 Messages as a Cell Array
firstMsgs = readMessages(bagselect2,1:10);