MATLAB Answers

How to get an array from a Rosbag

1 ビュー (過去 30 日間)
Paolino De Risi
Paolino De Risi 2021 年 9 月 16 日
コメント済み: Cam Salzberger 2021 年 9 月 17 日
Hi, I'm trying to plot a data from a rosbag, here what i did until now:
This struct is a 19153x1 cell and each element is a 1x1 struct with a velocity record, a 2x1 array.
Now, what i need is to create 1 column array with each wh_gazStruct.Velocity first element, but I can't find a solution. Until now I tryed:
wh_gaz_mat=cellfun(@(m) double(m.Velocity),wh_gazStruct);
but since the .Velocity record has two elements it doesn't work. How may I solve my problem?

回答 (1 件)

Cam Salzberger
Cam Salzberger 2021 年 9 月 16 日
I provided some guidance and sample code to a similar question here. That should help get you moving in the right direction!
  2 件のコメント
Cam Salzberger
Cam Salzberger 2021 年 9 月 17 日
Well, I don't know exactly what your messages look like. But if I set up my messages like this (to simulate using readMessages with DataFormat='struct'):
msg = rosmessage('sensor_msgs/JointState', 'DataFormat', 'struct');
n = 4;
msgs = cell(n, 1);
for k = 1:n
msgs{k} = msg;
msgs{k}.Velocity = [k ; -k];
Then I can do this:
[wh1, wh2] = cellfun(@getwheelsvelocities, msgs);
with your code as-provided, and it works just fine.
If you have any messages that do not have two entries in the Velocity field, then this code will fail.





Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by