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: bf_output_PLI.m
    path of file: ./repos/spm12/toolbox/DAiSS
    
    the code of the file until where you have to start completion: function mont = bf_output_PLI(BF, S)
% Generates a montage for source extraction, projects the sources one by
% one and computes phase lag index on the fly, which is written out with no
% need to call bf_write. Only one VOI allowed, which can be a sphere or a
% mask image.

% Copyright (C) 2015-2017 Wellcome Trust Centre for Neuroimaging & University of
% Zurich

% Dominik R Bach
% PLI computation using code published by Gerald Cooray (2010) Karolinska 
% Institutet: EFFECT OF DIABETES MELLITUS ON HUMAN BRAIN FUNCTION 
% (https://openarchive.ki.se/xmlui/bitstream/handle/10616/40241/ram_ber%C3%A4ttelse.pdf)
% with a method based on Stam CJ, Nolte G, Daffertshofer A (Hum Brain Mapp 2007)
% 
% $Id: bf_output_PLI.m 7706 2019-11-22 16:30:29Z spm $
%--------------------------------------------------------------------------
if nargin == 0
    label = cfg_entry;
    label.tag = 'label';
    label.name = 'Label';
    label.strtype = 's';
    label.help = {'Label for the reference VOI'};
    
    pos = cfg_entry;
    pos.tag = 'pos';
    pos.name = 'MNI coordinates';
    pos.strtype = 'r';
    pos.num = [1 3];
    pos.help = {'Locations for the reference VOI in MNI coordinates'};
    pos.val = {};
    
    radius = cfg_entry;
    radius.tag = 'radius';
    radius.name = 'Radius';
    radius.strtype = 'r';
    radius.num = [1 1];
    radius.val = {0};
    radius.help = {'Radius (in mm) for the reference VOIs (leave 0 for single point)'};
    
    voidef = cfg_branch;
    voidef.tag = 'voidef';
    voidef.name = 'VOI';
    voidef.val = {label, pos, radius};
    
    mask = cfg_files;
    mask.tag = 'mask';
    mask.name = 'MNI mask';
    mask.filter = 'image';
    mask.ufilter = '.*';
    mask.num     = [1 1];
    mask.help = {'Select a reference mask image'};
    
    maskdef = cfg_branch;
    maskdef.tag = 'maskdef';
    maskdef.name = 'Mask VOI';
    maskdef.val  = {label, mask};
    
    sourcefile = cfg_files;
    sourcefile.tag = 'sourcefile';
    sourcefile.name = 'Source file';
    sourcefile.filter = 'mat';
    sourcefile.num = [1 1];
    sourcefile.help = {'Select the M/EEG data file'};
    
    sourcefiledef = cfg_branch;
    sourcefiledef.tag = 'sourcefiledef';
    sourcefiledef.name = 'Source file';
    sourcefiledef.val = {label, sourcefile};
    sourcefiledef.help = {'Select an M/EEG file with channels corresponding to reference sources. Otherwise this file must exactly correspond to the file on which the BF was computed'};
    
    vois = cfg_repeat;
    vois.tag = 'vois';
    vois.name = 'Redefine reference VOIs';
    vois.num  = [1 1];
    vois.values = {voidef, maskdef, sourcefiledef};
    vois.val  = {};
    vois.help = {'Select the source VOI from which you would like to compute the PLI'};
    
    highpass = cfg_entry;
    highpass.tag = 'highpass';
    highpass.strtype = 'r';
    highpass.name = 'Highpass cutoff';
    highpass.num = [];
    highpass.val = {0};
    highpass.help = {'Highpass filter cutoff (4th order butterworth)'};
    
    lowpass = cfg_entry;
    lowpass.tag = 'lowpass';
    lowpass.name = 'Lowpass cutoff';
    lowpass.strtype = 'r';
    lowpass.num = [];
    lowpass.val = {300};
    lowpass.help = {'Lowpass filter cutoff (4th order butterworth)'};
    
    filtermethod = cfg_branch;
    filtermethod.tag = 'filtermethod';
    filtermethod.name = 'Filter reconstructed sources';

    
function mont = bf_output_PLI(BF, S)
% Generates a montage for source extraction, projects the sources one by
% one and computes phase lag index on the fly, which is written out with no
% need to call bf_write. Only one VOI allowed, which can be a sphere or a
% mask image.

% Copyright (C) 2015-2017 Wellcome Trust Centre for Neuroimaging & University of
% Zurich

% Dominik R Bach
% PLI computation using code published by Gerald Cooray (2010) Karolinska 
% Institutet: EFFECT OF DIABETES MELLITUS ON HUMAN BRAIN FUNCTION 
% (https://openarchive.ki.se/xmlui/bitstream/handle/10616/40241/ram_ber%C3%A4ttelse.pdf)
% with a method based on Stam CJ, Nolte G, Daffertshofer A (Hum Brain Mapp 2007)
% 
% $Id: bf_output_PLI.m 7706 2019-11-22 16:30:29Z spm $
%--------------------------------------------------------------------------
if nargin == 0
    label = cfg_entry;
    label.tag = 'label';
    label.name = 'Label';
    label.strtype = 's';
    label.help = {'Label for the reference VOI'};
    
    pos = cfg_entry;
    pos.tag = 'pos';
    pos.name = 'MNI coordinates';
    pos.strtype = 'r';
    pos.num = [1 3];
    pos.help = {'Locations for the reference VOI in MNI coordinates'};
    pos.val = {};
    
    radius = cfg_entry;
    radius.tag = 'radius';
    radius.name = 'Radius';
    radius.strtype = 'r';
    radius.num = [1 1];
    radius.val = {0};
    radius.help = {'Radius (in mm) for the reference VOIs (leave 0 for single point)'};
    
    voidef = cfg_branch;
    voidef.tag = 'voidef';
    voidef.name = 'VOI';
    voidef.val = {label, pos, radius};
    
    mask = cfg_files;
    mask.tag = 'mask';
    mask.name = 'MNI mask';
    mask.filter = 'image';
    mask.ufilter = '.*';
    mask.num     = [1 1];
    mask.help = {'Select a reference mask image'};
    
    maskdef = cfg_branch;
    maskdef.tag = 'maskdef';
    maskdef.name = 'Mask VOI';
    maskdef.val  = {label, mask};
    
    sourcefile = cfg_files;
    sourcefile.tag = 'sourcefile';
    sourcefile.name = 'Source file';
    sourcefile.filter = 'mat';
    sourcefile.num = [1 1];
    sourcefile.help = {'Select the M/EEG data file'};
    
    sourcefiledef = cfg_branch;
    sourcefiledef.tag = 'sourcefiledef';
    sourcefiledef.name = 'Source file';
    sourcefiledef.val = {label, sourcefile};
    sourcefiledef.help = {'Select an M/EEG file with channels corresponding to reference sources. Otherwise this file must exactly correspond to the file on which the BF was computed'};
    
    vois = cfg_repeat;
    vois.tag = 'vois';
    vois.name = 'Redefine reference VOIs';
    vois.num  = [1 1];
    vois.values = {voidef, maskdef, sourcefiledef};
    vois.val  = {};
    vois.help = {'Select the source VOI from which you would like to compute the PLI'};
    
    highpass = cfg_entry;
    highpass.tag = 'highpass';
    highpass.strtype = 'r';
    highpass.name = 'Highpass cutoff';
    highpass.num = [];
    highpass.val = {0};
    highpass.help = {'Highpass filter cutoff (4th order butterworth)'};
    
    lowpass = cfg_entry;
    lowpass.tag = 'lowpass';
    lowpass.name = 'Lowpass cutoff';
    lowpass.strtype = 'r';
    lowpass.num = [];
    lowpass.val = {300};
    lowpass.help = {'Lowpass filter cutoff (4th order butterworth)'};
    
    filtermethod = cfg_branch;
    filtermethod.tag = 'filtermethod';
    filtermethod.name = 'Filter reconstructed sources';
    filtermethod.val = {highpass, lowpass};
    
    method = cfg_menu;
    method.tag = 'method';
    method.name = 'Summary method';
    method.labels = {'max', 'svd', 'keep'};
    method.val = {'svd'};
    method.values = {'max', 'svd', 'keep'};
    method.help = {'How to summarise sources in the reference ROI'};
    
    mont = cfg_branch;
    mont.tag = 'PLI';
    mont.name = 'Phase Lag Index';
    mont.val  = {method, filtermethod, vois};
    return
elseif nargin < 2
    error('Two input arguments are required');
end