function [sl,mx,ig]=uca_calc_ig_fn(xx,yy)

  ll=length(xx);
  for ii=2:ll-1
    %spisthesplitlocation
    sp=xx(ii);
 
    %buildleftandrighttree
    xl=yy(xx<sp);
    xr=yy(xx>=sp);
 

    %length of the left tree
    l1=length(xl);
 
    %sum of class 1s
    n1=sum(xl);

    %sum of class 0s
    n2=l1-n1;


    %probabilities
    p1=n1/(n1+n2)+0.00001;
    p2=n2/(n1+n2)+0.00001;


    %entropy of the left tree
    en1 = -p1*log(p1)-p2*log(p2);


    %length of the right tree
    l2=length(xr);

    %sum of class 1s
    n1=sum(xr);

    %sum of class 0s
    n2=l2-n1;


    %probabilities
    p1=n1/(n1+n2)+0.00001;
    p2=n2/(n1+n2)+0.00001;


    %entropy of the right tree
    en2 = -p1*log(p1)-p2*log(p2);


    %Calculates information gain
    ig(ii-1)=1-((l1/ll)*en1 + (l2/ll)*en2);
  end

  %find the split location with the maximum information gain
  tmp=find(ig==max(ig));
  sl=tmp(1);
  mx=max(ig);
end