function out=avgAngle(dataCluster,roi)

% out=avgAngle(dataCluster,roi)

numFlies=length(dataCluster);

bins=0:2*pi/25:2*pi;

haall=zeros(numFlies,length(bins));

for i=1:numFlies
    fly=dataCluster{i};
    angle=fly.theta(find(fly.speed>.5 & fly.r<0.4*roi))-fly.direction(find(fly.speed>.5 & fly.r<0.4*roi));
    for j=1:length(angle)
        if angle(j)<0
            angle(j)=angle(j)+(2*pi);
        end
    end
    ha=histc(angle,bins);
    ha=ha/length(angle);
    haall(i,:)=ha;
end

out.angleavg=mean(haall);
out.angleSD=std(haall);
out.angleSEM=std(haall)/sqrt(numFlies);

