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: determine_griddim.m
    path of file: ./repos/fieldtrip/private
    
    the code of the file until where you have to start completion: function GridDim = determine_griddim(elec)


    
function GridDim = determine_griddim(elec)

% DETERMINE_GRIDDIM uses the labels and positions of electrodes in elec to
% determine the dimensions of each set of electrodes (i.e., electrodes with
% the same string, but different numbers)
%
% use as: 
%   GridDim = determine_griddim(elec)
%   where elec is a structure that contains an elecpos field and a label field
%   and GridDim(1) = number of rows and GridDim(2) = number of columns
%   
% See also FT_ELECTRODEREALIGN

% Copyright (C) 2017-2018, Arjen Stolk, Sandon Griffin
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
%    FieldTrip is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    FieldTrip is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id$

% determine electrode range
digits = regexp(elec.label, '\d+', 'match');
elec.maxdigit = 1;
elec.mindigit = Inf;
for l=1:numel(digits)
  ElecStrs{l,1} = regexprep(elec.label{l}, '\d+(?:_(?=\d))?', ''); % without electrode numbers
  elec.ElecLab{l,1} = digits{l}{1}; % use first found digit
  if str2num(digits{l}{1}) > elec.maxdigit
    elec.maxdigit = str2num(digits{l}{1});
  end