function angleF=angleFactor(x)
global edges2
global avg2

if x<=-180
    x=x+360;
end
if x>180
    x=x-360;
end

if x<=edges2(1)
    percent=x/edges2(1);
    angleF=0+percent*avg2(1);
end
if edges2(end)<=x
    percent=(x-edges2(end))/(180-edges2(end));
    angleF=(1-percent)*avg2(end)+0;
end 
for n=1:length(edges2)-1
    if edges2(n)<=x & x<=edges2(n+1)
        percent=(x-edges2(n))/(edges2(n+1)-edges2(n));
        angleF=(1-percent)*avg2(n)+percent*avg2(n+1);
    end
end