How to pick the content out of a ROS Point message?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Andreas Schwager
am 27 Aug. 2021
Beantwortet: Cam Salzberger
am 27 Aug. 2021
Hello,
How to pick the content out of a ROS Point message?
Or how to get members out of a cell arry into a simple array?
The following code runs, but is there any way avoiding the for-loop and cpoying the data direct from cell array member to an array?
Euler = readMessages(BagFile,startIdx:endIdx);
for ii = 1:size(Euler,1)
yaw(ii) = Euler{ii}.Point.X;
pitch(ii) = Euler{ii}.Point.Y;
roll(ii) = Euler{ii}.Point.Z;
end
0 Kommentare
Akzeptierte Antwort
Cam Salzberger
am 27 Aug. 2021
Hello Andreas,
cellfun is useful for operations like this, where you want to do the same thing on each cell. Probably the best and most efficient code would look something like this:
% Use struct message format for faster read time
Euler = readMessages(BagFile,startIdx:endIdx,"DataFormat","struct");
[yaw, pitch, roll] = cellfun(@getXYZFromPoint, Euler);
function [x, y, z] = getXYZFromPoint(msg)
% Extract internal message first for efficiency
% (matters more for more nested messages)
vec = msg.Point;
x = vec.X;
y = vec.Y;
z = vec.Z;
end
If on the other hand you wanted to turn the cell array of messages (or message structs) into a message object or struct array, you could just do this:
EulerArr = [Euler{:}];
Note that all messages have to have the same structure for that to work.
-Cam
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu ROS Log Files and Transformations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!