You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: plinprojn.m
    path of file: ./repos/spm12/external/fieldtrip/utilities/private
    
    the code of the file until where you have to start completion: function [proj, dist] = plinprojn(l1,l2,r,flag)


    
function [proj, dist] = plinprojn(l1,l2,r,flag)

% PLINPROJN projects a point onto a line or linepiece
%
% [proj, dist] = plinprojn(l1, l2, r, flag)
% 
% where l1 and l2 are Nx3 matrices with the begin and end