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: TBR.m
    path of file: ./repos/bspm/thirdparty/MRtools_2015-08-21/TBR
    
    the code of the file until where you have to start completion: function  TBR(fn,targets,controls,subset,tag,outdir)
% This function implements the TBR functional mapping procedure.  An SPM 
% installation is required.
%
% FN - A cell array of input files (expects 4D-Nifti files)
%
% TARGETS - a cell array of file paths to target template maps.
%
% CONTROLS - a cell array of file paths to template maps that should be controled for.
%
% SUBSET - an OPTIONAL index of time points to include. Inputs should be vectors nested within a cell array (e.g. {[1:50 60:100] [1:99]}.
%
% TAG - an optional postfix for output directory names.
%
% OUTDIR - an option input to specify the path to the output directory.
% 
% Written by Aaron P. Schultz - aschultz@martinos.org
%
% Copyright (C) 2013,  Aaron P. Schultz
%
% Supported in part by the NIH funded Harvard Aging Brain Study (P01AG036694) and NIH R01-AG027435 
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.

hm = pwd;

if nargin<3
    controls = [];
end

if nargin<5

    
function  TBR(fn,targets,controls,subset,tag,outdir)
% This function implements the TBR functional mapping procedure.  An SPM 
% installation is required.
%
% FN - A cell array of input files (expects 4D-Nifti files)
%
% TARGETS - a cell array of file paths to target template maps.
%
% CONTROLS - a cell array of file paths to template maps that should be controled for.
%
% SUBSET - an OPTIONAL index of time points to include. Inputs should be vectors nested within a cell array (e.g. {[1:50 60:100] [1:99]}.
%
% TAG - an optional postfix for output directory names.
%
% OUTDIR - an option input to specify the path to the output directory.
% 
% Written by Aaron P. Schultz - aschultz@martinos.org
%
% Copyright (C) 2013,  Aaron P. Schultz
%
% Supported in part by the NIH funded Harvard Aging Brain Study (P01AG036694) and NIH R01-AG027435 
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.

hm = pwd;

if nargin<3
    controls = [];
end

if nargin<5
    tag = '';
end

if nargin<6 || isempty(outdir);
    outdir = hm;
end

if ischar(fn);
    fn = cellstr(fn);
end