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: canlab_list_files.m
    path of file: ./repos/CanlabCore/CanlabCore/Filename_tools
    
    the code of the file until where you have to start completion: function [names, isfile, isdir, hasduplicates] = canlab_list_files(varargin)
% [names, isfile, isdir, hasduplicates]  = canlab_list_files(dir1, dir2, dir3, etc.)
%
% Lists files in a series of subfolders in a particular order.
% Enter as many dirs as you want, which are subfolders.
% If a dir is a cell array of names, this function will look in all combos
% of those cells with other dir strings, in order.
% dir1...n strings are concatenated in order.
%
% Returns:
% Vector of whether each name in names is an existing file, and whether
% each is an existing directory
%
% e.g.,
% subjects = {'nsf1' 'nsf2' 'NSF909'};
% names = canlab_list_files(subjects, 'Structural', 'SPGR', 'wspgr.img')
% names = canlab_list_files(pwd, subjects, 'Structural', 'SPGR', 'wspgr.img')
% 
% Return list of whether each is an existing file or dir
% [names, isfile, isdir, hasduplicates] = canlab_list_files(pwd, subjects, 'Structural', 'SPGR', 'wspgr.img')

    
function [names, isfile, isdir, hasduplicates] = canlab_list_files(varargin)
% [names, isfile, isdir, hasduplicates]  = canlab_list_files(dir1, dir2, dir3, etc.)
%
% Lists files in a series of subfolders in a particular order.
% Enter as many dirs as you want, which are subfolders.
% If a dir is a cell array of names, this function will look in all combos
% of those cells with other dir strings, in order.
% dir1...n strings are concatenated in order.
%
% Returns:
% Vector of whether each name in names is an existing file, and whether
% each is an existing directory
%
% e.g.,
% subjects = {'nsf1' 'nsf2' 'NSF909'};
% names = canlab_list_files(subjects, 'Structural', 'SPGR', 'wspgr.img')
% names = canlab_list_files(pwd, subjects, 'Structural', 'SPGR', 'wspgr.img')
% 
% Return list of whether each is an existing file or dir
% [names, isfile, isdir, hasduplicates] = canlab_list_files(pwd, subjects, 'Structural', 'SPGR', 'wspgr.img')
%
% Make string matrix:
% names = char(names{:});

d = varargin;

names = {};

for i = 1:length(d)
    
    n = length(names);
    
    if iscell(d{i})
        
        if isempty(names)
            names = d{i};
            if diff(size(names)) % is row
                names = names';
            end