How to pick the content out of a ROS Point message?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Cam Salzberger
2021년 8월 27일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 ROS Log Files and Transformations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!