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: findElements.m
    path of file: ./repos/ValoMC
    
    the code of the file until where you have to start completion: function elements = findElements(vmcmesh, querystring, varargin)
%FINDELEMENTS Finds elements from the mesh
%
% USAGE:
%
%       elements = findElements(vmcmesh, querystring, varargin)
%
% DESCRIPTION:
%
%       This function can be used to find elements from the mesh.
%       A complete description is given in the homepage (see below).
%
% INPUT:
%
%       vmcmesh       - mesh structure, contains the geometry of the system
%
%       querystring, optional arguments
%
%       2D mesh (row size)
%
%          'rectangle', position(2), width (1), height (1)
%          'circle', location (2), radius (1)
%          'inverse', elements (number of elements in the selection)
%          'location', location (2)
%          'region', region_BH (2)
%
%       3D mesh (row size)
%
%          'cylinder', origin (3), direction (3), radius (1)
%          'box', origin (2), xsize (1), ysize (1), zsize (1)
%          'sphere', location (3), radius (1)
%          'inverse', elements (number of elements in the selection)
%          'location', location (3)

    
function elements = findElements(vmcmesh, querystring, varargin)
%FINDELEMENTS Finds elements from the mesh
%
% USAGE:
%
%       elements = findElements(vmcmesh, querystring, varargin)
%
% DESCRIPTION:
%
%       This function can be used to find elements from the mesh.
%       A complete description is given in the homepage (see below).
%
% INPUT:
%
%       vmcmesh       - mesh structure, contains the geometry of the system
%
%       querystring, optional arguments
%
%       2D mesh (row size)
%
%          'rectangle', position(2), width (1), height (1)
%          'circle', location (2), radius (1)
%          'inverse', elements (number of elements in the selection)
%          'location', location (2)
%          'region', region_BH (2)
%
%       3D mesh (row size)
%
%          'cylinder', origin (3), direction (3), radius (1)
%          'box', origin (2), xsize (1), ysize (1), zsize (1)
%          'sphere', location (3), radius (1)
%          'inverse', elements (number of elements in the selection)
%          'location', location (3)
%          'region', region_BH (3)
%
% SEE ALSO:
%
% Detailed documentation of the function is given in
% https://inverselight.github.io/ValoMC/findingelements.html
%
% This function is provided with ValoMC

    if(size(vmcmesh.H,2) == 3)
        % 2D
        if(strcmp(querystring, 'rectangle'))
            elements = findElementsInsideRectangle(vmcmesh, varargin{2}, varargin{3}, varargin{1});
            % input is (vmcmesh, width, height, location)
        elseif(strcmp(querystring, 'circle'))
   	        elements = findElementsInsideCircle(vmcmesh, varargin{2}, varargin{1});
        elseif(strcmp(querystring, 'inverse'))
            arr = 1:size(vmcmesh.H);
            elements = setdiff(arr, [varargin{1}]);
        elseif(strcmp(querystring, 'location'))
            elements =  findElementsNearest(vmcmesh, varargin{1});
        elseif(strcmp(querystring, 'region'))
            warning('2d region not yet implemented')
        end