I am trying to analyse data from a rosbag from a turtlebot run. I have Pose_Array message which contains about 10,000 particles and I want to computer the mean of the X and Y position of these particles. When I try to access as follows:
rb = rosbag('test.bag');
tb_particle_bag = select(rb,'Topic','/particlecloud');
msg = readMessages(tb_particle_bag,1);
Then when I run the following I see...
10000×1 ROS Pose message array with properties:
However when I try to access the X-coordinates of all the particles I see the follwing error:
Expected one output from a curly brace or dot indexing expression, but there were 10000 results.
The only work around I have found to this is to individually access each particles and read its x value in a for loop and this turns out to be extremely slow as follows:
for i = 1:tb_particle_bag.NumMessages
msg = readMessages(tb02_gt_particle_bag,i);
sum = [0 0];
for j = 1:size(b,1)
sum = sum + [p.X p.Y];
This above method takes about 2.5secs for each PoseArray message in the rosbag and makes the process excruciatingly long. Is there a more efficient way to do this?