function [res] = contactstime2image( input_matrix, total )
% Create a symmetric matrix with the total duration of contacts between nodes i and j
%   input_matrix: the imported dataset, in matrix form
%   total: the total number of nodes

res = zeros(total);

s = size(input_matrix);

nrows = s(1);

for ii = 1:nrows
    if (input_matrix(ii,1) <= total) && (input_matrix(ii,2) <= total)   % ignore node IDs higher than the total number
        time_interval = input_matrix(ii,4) - input_matrix(ii,3);
        if (time_interval == 0) % Round up if a contact begins and ends in the same second
            time_interval = 1; 
        end
        res(input_matrix(ii,1), input_matrix(ii,2)) = res(input_matrix(ii,1), input_matrix(ii,2)) + time_interval;
        res(input_matrix(ii,2), input_matrix(ii,1)) = res(input_matrix(ii,2), input_matrix(ii,1)) + time_interval;
    end
end


return;
end

