%% Function DLC

% Extracts data from specific file analysed by DLC with specific parameters
% - currfoldersv: specific path of folder of .csv files
% - loads_csv: dir return of folder with .csv files
% - idxx: X indexes of tracked body parts
% - idxy: Y indexes of tracked body parts
% - px_to_cm: pixel to centimeter conversion constant
% - L: 1,2,...,N vector indexing the number of analysing .csv files

function travelled_ourDLC = function_DLC(currfoldercsv, loads_csv, idxx, idxy, px_to_cm, L)

    travelled_ourDLC = [];
    for i = L
        file = readmatrix([currfoldercsv, loads_csv(i).name], 'Range', [4 2]);
        x = mean(file(:, idxx), 2);
        y = mean(file(:, idxy), 2);
        prev = [x(1:end-1), y(1:end-1)];
        next = [x(2:end), y(2:end)];
        for j = 1:length(prev)
            dists_px(j) = distance(prev(j, 1:2), next(j, 1:2));
        end
        travelled_ourDLC = [travelled_ourDLC, dists_px];
    end
    travelled_ourDLC = travelled_ourDLC .* px_to_cm; % cm conversion

end