Files
MatLabPlotter/assets/vector2timetable.m
2025-06-30 18:12:50 +02:00

34 lines
1.0 KiB
Matlab

function [data] = vector2timetable(data_path, varargin)
%VECTOR2TIMETABLE Load vector datalogger data and convert it to a timetable
% Specify the path to the data in DATA_PATH, and optionally specify names
% of signals to load.
raw_data = load(data_path, varargin{:});
fn = fieldnames(raw_data);
base_ts = datetime(0, 1, 0);
for i=1:numel(fn)
var = raw_data.(fn{i});
timestamps = days(var(:,1)) + base_ts;
tt{i} = array2timetable( ...
var(:,2), ...
"RowTimes",timestamps, ...
"VariableNames",{fn{i}} ...
);
end
try
data = synchronize(tt{:},"union","nearest");
catch
try
for i=1:length(tt)
data_unsorted = tt{i};
data_all{i} = sortrows(data_unsorted);
end
data = synchronize(data_all{:},"union","previous");
catch
data = tt{:};
end
end
% union -> union of the row times
% method -> fill gaps in output with nearest neighbor in the input timetable
end