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: expand_nii_scan.m
    path of file: ./repos/bspm/thirdparty/bramila/external/ISC_toolbox/niftitools
    
    the code of the file until where you have to start completion: %  Expand a multiple-scan NIFTI file into multiple si
    
function expand_nii_scan(filename, img_idx, newpath)

   if ~exist('newpath','var'), newpath = pwd; end
   if ~exist('img_idx','var'), img_idx = 1:get_nii_frame(filename); end

   for i=img_idx
      nii_i = load_untouch_nii(filename, i);

      fn = [nii_i.fileprefix '_' sprintf('%04d',i)];
      pnfn = fullfile(newpath, fn);

      save_untouch_nii(nii_i, pnfn);
   end