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: opt_thresh.m
    path of file: ./repos/bspm/thirdparty/spm8/toolbox/Masking
    
    the code of the file until where you have to start completion: function [thr Vthr] = opt_thresh(in, optfunc, out)
%opt_thresh - determine an optimal threshold to binarise a continuous image
% [thr Vthr] = opt_thresh(input, optfunc, outname)
%

    
function [thr Vthr] = opt_thresh(in, optfunc, out)
%opt_thresh - determine an optimal threshold to binarise a continuous image
% [thr Vthr] = opt_thresh(input, optfunc, outname)
%
% If outname is included (even if empty), then the optimally thresholded
% volume is written to disk, and a volume handle is returned in Vthr
%
% optfunc is a function handle (or string containing one) that finds the
% optimal threshold. Two alternatives are included:
%
% (i)  Maximising correlation between original and binarised result
%      '@opt_thr_corr' (also default if optfunc is empty or unspecified)
% (ii) An estimate of the statistical anti-mode '@opt_thr_antimode'
%
% The first option is equivalent to maximising the t-value for a two-sample
% t-test between the below- and above-threshold parts of the image, which
% in turn is similar to the histogram-based criterion in Otsu's method.
%
% See also: make_average, make_majority_mask
%
% Please reference:
%  Ridgway et al. (in press) Neuroimage
%  http://dx.doi.org/10.1016/j.neuroimage.2008.08.045
%  pre-print available from http://eprints.ucl.ac.uk/13060/
%
% If using opt_thr_antimode, please also reference:
%  Luo and Nichols (2003) Neuroimage 19, 1014-1032
%  http://dx.doi.org/10.1016/S1053-8119(03)00149-6
%  pre-print available from http://www.sph.umich.edu/ni-stat/SPMd/SPMd.pdf
%
% Email ged.ridgway@gmail.com with any questions
% http://www.cs.ucl.ac.uk/staff/g.ridgway/masking

[spm5 select fparts] = check_spm_setup;

% Check if called from batch system
if nargin == 1 && isstruct(in) && isfield(in, 'inname')
    job     = in;
    in      = job.inname;
    optfunc = job.optfunc;
    [pth nam ext num] = spm_fileparts(job.outname);
    if isempty(pth)
        % {''} seems to end