opts = delimitedTextImportOptions("NumVariables", 1);
opts.DataLines = [1, Inf];
opts.VariableNames = "txt";
test1 = readtable("test1.txt", opts);
tokens = regexp(test1.txt, 'frame (\d+) ts (\d+.\d+)', 'tokens');
frame_ts = cell2mat(cellfun(@str2double,[tokens{:}]','UniformOutput',false));
tokens = regexp(test1.txt, '^loc (-?\d+.\d+) (-?\d+.\d+) (-?\d+.\d+)', 'tokens');
loc = cell2mat(cellfun(@str2double,[tokens{:}]','UniformOutput',false));
if size(frame_ts,1) ~= size(loc,1)
error('''frame_ts'' and ''loc'' have different number of rows.')
end
T = array2table([frame_ts, loc], 'VariableNames', {'frame', 'timestamp', 'loc_x', 'loc_y', 'loc_z'});
head(T)
Best Answer