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: undobalancing.m
    path of file: ./repos/bspm/thirdparty/spm12/external/fieldtrip/fileio/private
    
    the code of the file until where you have to start completion: function sens = undobalancing(sens)


    
function sens = undobalancing(sens)

% UNDOBALANCING removes all balancing coefficients from the gradiometer sensor array
%
% This is used in CHANNELPOSITION, FT_PREPARE_LAYOUT, FT_SENSTYPE

while isfield(sens, 'balance') && isfield(sens.balance, 'current') && ~strcmp(sens.balance.current, 'none')
  fnames = setdiff(fieldnames(sens.balance), 'current');
  indx   = find(ismember(fnames, sens.balance.current));
  
  if length(indx)==1,
    % undo the synthetic gradient balancing
    fprintf('undoing the %s balancing for the gradiometer definition\n', sens.balance.current);
    
    % if ft_componentanalysis was followed by ft_rejectcomponent, the balancing matrix is rank deficient
    % leading to problems in the correct allocation of the coils to the channels
    if strcmp(sens.balance.current, 'invcomp') && strcmp(sens.balance.previous{1}, 'comp')
      tra1 = full(sens.balance.invcomp.tra);
      tra2 = full(sens.balance.comp.tra);
      tra3 = tra1;
      tmp  = tra1*tra2;
      tmp  = null(tmp); % nullspace after ft_componentanalysis and ft_rejectcomponent
      tmp  = tmp*tmp';  % this is the part which was removed at some point
      [ix,iy]     = match_str(sens.balance.comp.labelold, sens.balance.invcomp.labelnew);
      tra3(iy,iy) = (eye(numel(ix))+tmp(ix,ix))*tra1(iy,iy);
      sens.balance.invcomp.tra = tra3;
      % FIXME check whether this is robust
    end