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: total_signed_occurrences.m
    path of file: ./repos/gptoolbox/mesh
    
    the code of the file until where you have to start completion: function [S,uF,I,J] = total_signed_occurrences(F)
  % TOTAL_SIGNED_OCCURRENCES Compute the total number of times each polygon in F
  % occurs.
  %
  % Inputs:
  %   F  #F by d list of simple polygon indices
  % Outputs:
  %   S  #uF list of total signed occurances
  %   uF  #uF by d list of unique polygons (sorted)
  %   I  #uF list of indices into F
  %   J  #F list of indices into uF
  %
  m = size(F,1);
  d = size(F,2);
  % In general d>3 can't just sort
  sF = F;
  MN = min(sF,[],2);

    
function [S,uF,I,J] = total_signed_occurrences(F)
  % TOTAL_SIGNED_OCCURRENCES Compute the total number of times each polygon in F
  % occurs.
  %
  % Inputs:
  %   F  #F by d list of simple polygon indices
  % Outputs:
  %   S  #uF list of total signed occurances
  %   uF  #uF by d list of unique polygons (sorted)
  %   I  #uF list of indices into F
  %   J  #F list of indices into uF
  %
  m = size(F,1);
  d = size(F,2);
  % In general d>3 can't just sort
  sF = F;
  MN = min(sF,[],2);
  % rotate until smallest index is first
  for p = 1:d
    bad = MN~=sF(:,1);
    sF(bad,:) = sF(bad,[2:d 1]);
  end