-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtpload.m
executable file
·47 lines (40 loc) · 1.22 KB
/
rtpload.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function [time, data] = rtpload(filename)
%
% [time, data] = rtpload(filename)
%
% Load data from a ROS message file, created with
% a 'rostopic echo -p topic > filename' command.
%
% filename name (including path) of data file
% time Nx1 vector of ROS times, when the
% individual messages were received
% data structure of Nx1 vectors, corresponding
% to the fields in the message data
% Note: rostopic saves a header line with information
% about the data. The first column is the time the
% message was received, the rest are message fields.
% Get the header line - which includes the data format.
fid = fopen(filename);
if (fid < 0)
error('Unable to open file %s', filename);
end
line = fgetl(fid);
fclose(fid);
% Make sure the file contains something.
if (line <0)
error('Empty file %s', filename);
end
% Load the actual data.
raw = load(filename);
% Restructure the data.
column = 0;
while (~isempty(line))
[token,line] = strtok(line,'%,');
column = column+1;
eval([token ' = raw(:,' num2str(column) ');']);
end
% Move to the correct output variables. The first column
% is 'time', the rest are 'field.item1' 'field.item2' etc.
time = time;
data = field;
return;