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");
        % union -> union of the row times
        % method -> fill gaps in output with nearest neighbor in the input timetable
    catch
        try
            for i=1:length(tt)
                tt{i} = sortrows(tt{i});
            end
            data = synchronize(tt{:},"union","nearest");
        catch
            data = tt{:};
        end
    end
end

