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: combineClusters.m
    path of file: ./repos/fieldtrip/plotting/private
    
    the code of the file until where you have to start completion: function cluster = combineClusters(labelmat, spatdimneighbstructmat, total)

% COMBINECLUSTERS is a helper function for FINDCLUSTER. It searches for
% adjacent clusters in neighbouring channels and combines them.

% A mex-file is available for this function, as it can take quite long.

replaceby=1:total;
spatdimlength = size(labelmat, 1);
for spatdimlev=1:spatdimlength
  neighbours=find(spatdimneighbstructmat(spatdimlev,:));
  for nbindx=neighbours

    
function cluster = combineClusters(labelmat, spatdimneighbstructmat, total)

% COMBINECLUSTERS is a helper function for FINDCLUSTER. It searches for
% adjacent clusters in neighbouring channels and combines them.

% A mex-file is available for this function, as it can take quite long.

replaceby=1:total;
spatdimlength = size(labelmat, 1);
for spatdimlev=1:spatdimlength
  neighbours=find(spatdimneighbstructmat(spatdimlev,:));
  for nbindx=neighbours
    indx = find((labelmat(spatdimlev,:)~=0) & (labelmat(nbindx,:)~=0));
    for i=1:length(indx)
      a = labelmat(spatdimlev, indx(i));
      b = labelmat(nbindx, indx(i));
      if replaceby(a)==replaceby(b)
        % do nothing
        continue;
      elseif replaceby(a)<replaceby(b)
        % replace all entries with content replaceby(b) by replaceby(a).
        replaceby(find(replaceby==replaceby(b))) = replaceby(a); 
      elseif replaceby(b)<replaceby(a)
        % replace all entries with content replaceby(a) by replaceby(b).
        replaceby(find(replaceby==replaceby(a))) = replaceby(b); 
      end