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: ft_plot_montage.m
    path of file: ./repos/fieldtrip/plotting
    
    the code of the file until where you have to start completion: function ft_plot_montage(dat, varargin)

% FT_PLOT_MONTAGE makes a montage of a 3-D array by selecting slices at regular distances
% and combining them in one large 2-D image.  Note that the montage of MRI slices is not to
% be confused with the EEG montage, which is a way of specifying the reference scheme
% between electrodes.
%
% Use as
%   ft_plot_montage(dat, ...)
% where dat is a 3-D array.
% 
% Additional options should be specified in key-value pairs and can be

    
function ft_plot_montage(dat, varargin)

% FT_PLOT_MONTAGE makes a montage of a 3-D array by selecting slices at regular distances
% and combining them in one large 2-D image.  Note that the montage of MRI slices is not to
% be confused with the EEG montage, which is a way of specifying the reference scheme
% between electrodes.
%
% Use as
%   ft_plot_montage(dat, ...)
% where dat is a 3-D array.
% 
% Additional options should be specified in key-value pairs and can be
%   'transform'     = 4x4 homogeneous transformation matrix specifying the mapping from voxel space to the coordinate system in which the data are plotted.
%   'location'      = 1x3 vector specifying a point on the plane which will be plotted, the coordinates are expressed in the coordinate system in which the data will be plotted. location defines the origin of the plane
%   'orientation'   = 1x3 vector specifying the direction orthogonal through the plane which will be plotted (default = [0 0 1])
%   'srange'        = 
%   'slicesize'     = 
%   'nslice'        = scalar, number of slices
%   'maskstyle'     = string, 'opacity' or 'colormix', defines the rendering
%   'background'    = needed when maskstyle is 'colormix', 3D-matrix with
%                     the same size as the data matrix, serving as
%                     grayscale image that provides the background
% 
% See also FT_PLOT_ORTHO, FT_PLOT_SLICE, FT_SOURCEPLOT

% undocumented, these are passed on to FT_PLOT_SLICE
%   'intersectmesh'  = triangulated mesh through which the intersection of the plane will be plotted (e.g. cortical sheet)
%   'intersectcolor' = color for the intersection

% Copyrights (C) 2012, Jan-Mathijs Schoffelen
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
%    FieldTrip 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
%    (at your option) any later version.
%
%    FieldTrip 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.
%
%    You should have received a copy of the GNU General Public License
%    along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id$

transform       = ft_getopt(varargin, 'transform', eye(4));
loc             = ft_getopt(varargin, 'location');
ori             = ft_getopt(varargin, 'orientation');
srange          = ft_getopt(varargin, 'slicerange');
slicesize       = ft_getopt(varargin, 'slicesize');
nslice          = ft_getopt(varargin, 'nslice');
backgroundcolor = ft_getopt(varargin, 'backgroundcolor', [0 0 0]);

% the intersectmesh and plotmarker options are passed on to FT_PLOT_SLICE
dointersect = ~isempty(ft_getopt(varargin, 'intersectmesh'));
domarker    = ~isempty(ft_getopt(varargin, 'plotmarker'));

% set the location if empty
if isempty(loc) && (isempty(transform) || isequal(transform, eye(4)))
  % go to the middle of the volume if the data seem to be in voxel coordinates
  loc = size(dat)./2;
elseif isempty(loc)
  % otherwise take the origin of the coordinate system
  loc = [0 0 0];
end