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: prepare_mesh_hexahedral.m
    path of file: ./repos/fieldtrip/private
    
    the code of the file until where you have to start completion: function mesh = prepare_mesh_hexahedral(cfg, mri)

% PREPARE_MESH_HEXAHEDRAL
%
% Configuration options for generating a regular 3-D grid
%   cfg.tissue     = cell with the names of the compartments that should be meshed
%   cfg.shift
%   cfg.background
%
% See also PREPARE_MESH_SEGMENTATION, PREPARE_MESH_MANUAL, PREPARE_MESH_HEADSHAPE

% Copyrights (C) 2012-2013, Johannes Vorwerk
% Copyrights (C) 2020, Jan-Mathijs Schoffelen
%
% $Id$

% ensure that the input is consistent with what this function expects
mri = ft_checkdata(mri, 'datatype', {'segmentation'}, 'segmentationstyle', 'indexed');

% The support fo
    
function create_elements

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function creating the nodes and assigning coordinates in the [0, x_dim]x[0,
% y_dim]x[0, z_dim] box. for details on the node-numbering see comments for
% create_elements.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function nodes = create_nodes(dim)

x_dim = dim(1);
y_dim = dim(2);
z_dim = dim(3);
nodes = zeros(((x_dim + 1)*(y_dim + 1)*(z_dim + 1)), 3);
% offset vector for node coordinates
b = 0:((x_dim + 1)*(y_dim + 1)*(z_dim + 1)-1);

% assign coordinates within the box
nodes(:, 1) = mod(b, (x_dim+1));
nodes(:, 2) = mod(fix(b/(x_dim+1)), (y_dim+1));
nodes(:, 3) = fix(b/((x_dim + 1)*(y_dim+1)));

end