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: VBA_spm_dcm_batch.m
    path of file: ./repos/VBA-toolbox/thrid-party/spm
    
    the code of the file until where you have to start completion: function [err,F,DCMnames] = VBA_spm_dcm_batch(DCM0dir,newVOIdir,newSPMdir,Unames,Ynames,est)
% replicates one single subject DCM analysis over a set of subjects
% function [err,F] = spm_dcm_batch(DCM0dir,newVOIdir,newSPMdir,Unames,Ynames)
% IN:
%   - DCM0dir: directory where the original DCM files to be cloned are
%   stored
%   - newVOIdir: nsX1 cell-array of directories where the VOI files are
%   stored
%   - newSPMdir: nsX1 cell-array of directories where the SPM files are
%   stored
%   - Unames: nsX1 cell array of ndcmX1 cell arrays of input names. For
%   each of the ns subjects, the function will look for each one of them in
%   the SPM file. NB: the order should match the original DCM structure. If
%   empty or unspecified, these will be set to the names of the inputs in
%   the original DCM structure
%   - Ynames: nsX1 cell array of ndcmX1 cell arrays of ROI names. For
%   each of the ns subjects, the function will look for each one of them in
%   the VOI files. NB: the order should match the original DCM structure.
%   If empty or unspecified, these will be set to the names of the ROIs in
%   the original DCM structure.
%   - est: flag for DCM estimation (1: estimate, 0: do not estimate)
% OUT:
%   - err: nsXndcm array of error flags. It is 0 if DCM appropriately
%   cloned, 1 problem with ROIs, 2 if problem with inputs, 3 if problem
%   with the original DCM and 4 if problem when saving the DCM structure, 5

    
function [err,F,DCMnames] = VBA_spm_dcm_batch(DCM0dir,newVOIdir,newSPMdir,Unames,Ynames,est)
% replicates one single subject DCM analysis over a set of subjects
% function [err,F] = spm_dcm_batch(DCM0dir,newVOIdir,newSPMdir,Unames,Ynames)
% IN:
%   - DCM0dir: directory where the original DCM files to be cloned are
%   stored
%   - newVOIdir: nsX1 cell-array of directories where the VOI files are
%   stored
%   - newSPMdir: nsX1 cell-array of directories where the SPM files are
%   stored
%   - Unames: nsX1 cell array of ndcmX1 cell arrays of input names. For
%   each of the ns subjects, the function will look for each one of them in
%   the SPM file. NB: the order should match the original DCM structure. If
%   empty or unspecified, these will be set to the names of the inputs in
%   the original DCM structure
%   - Ynames: nsX1 cell array of ndcmX1 cell arrays of ROI names. For
%   each of the ns subjects, the function will look for each one of them in
%   the VOI files. NB: the order should match the original DCM structure.
%   If empty or unspecified, these will be set to the names of the ROIs in
%   the original DCM structure.
%   - est: flag for DCM estimation (1: estimate, 0: do not estimate)
% OUT:
%   - err: nsXndcm array of error flags. It is 0 if DCM appropriately
%   cloned, 1 problem with ROIs, 2 if problem with inputs, 3 if problem
%   with the original DCM and 4 if problem when saving the DCM structure, 5
%   if DCM could not be inverted and 6 if it could not be saved.
%   - F: nsXndcmX2 array of free energies.
%   - DCMnames: ndcmX1 cell array of DCM names

ns = length(newVOIdir);
if ~exist('Unames','var') || isempty(Unames)
    for i=1:ns
        Unames{i} = [];
    end