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: icatb_convertMat2Img.m
    path of file: ./repos/gift/GroupICAT/icatb/icatb_scripts
    
    the code of the file until where you have to start completion: function icatb_convertMat2Img(matFile, templateFile, pixdim)
% Converts .mat to image format and places the images in the directory
% where the .mat file resides.
%
% Inputs:
% 1. matFile - Full file path of the MAT file
% 2. templateFile - Full file path of the template image file that the
% resulting images will use.
% 3. pixdim - Pixel dimensions (Optional variable)



    
function icatb_convertMat2Img(matFile, templateFile, pixdim)
% Converts .mat to image format and places the images in the directory
% where the .mat file resides.
%
% Inputs:
% 1. matFile - Full file path of the MAT file
% 2. templateFile - Full file path of the template image file that the
% resulting images will use.
% 3. pixdim - Pixel dimensions (Optional variable)


if ~exist('templateFile', 'var') | isempty(templateFile)
    % get the volume information from template file
    templateFile = which('nsingle_subj_T1_2_2_5.nii');
end