T=readtable('FILE.csv'); %type here the name of the file with the X/Y coordinates
MicrobeNo=T{1:end, 13:13};
x=T{1:end, 3:3}; %type here the column of the x information
y=T{1:end, 4:4};%type here the column of the y information
s=T{1:end, 6:6} %type here the column of the speed information


for i = 1:MicrobeNo(end)
    LenghtTrack(i)=numel(find(MicrobeNo==i));
end;
vek= cumsum(LenghtTrack);
 
%calculation of angles of first microbe
for a = 1:vek(1)-2
      
      xx12(a)= x(a+1)-x(a);
    yy12(a)= y(a+1)-y(a);
    xx23(a)= x(a+1+1)-x(a+1);
    yy23(a)= y(a+1+1)-y(a+1);
    DirChange1(a) = atan2(xx12(a)*yy23(a)-xx23(a)*yy12(a), xx12(a)*xx23(a)+yy12(a)*yy23(a))
 winkel1(a) = rad2deg(DirChange1(a));
end;



for d = 1:(length(vek)-1)
for ii = vek(d)+1:vek(d+1)-2

     x12(ii, d)= x(ii+1)-x(ii);
   y12(ii, d)= y(ii+1)-y(ii);
    x23(ii, d)= x(ii+1+1)-x(ii+1);
    y23(ii, d)= y(ii+1+1)-y(ii+1);

end;
end;
MM = atan2(x12.*y23-x23.*y12, x12.*x23+y12.*y23)
%calculation of angles of all microbes after first microbe
winkel = rad2deg(MM);
 Z = zeros(ii, 1);
    Z(1:length(winkel1),1) = winkel1;
    ZN = [Z winkel]
    meanangle1 = mean(winkel1);
    stda1= std(winkel1);
    ms1=mean(s(1+1:vek(1)))
    std1=std(s(1+1:vek(1)))
    nna1=length(find(winkel1<0))/length(winkel1)
    npa1=length(find(winkel1>0))/length(winkel1)
 nnn1=length(find(abs(winkel1)< 20))/length(winkel1)
for d = 1:(length(vek)-1)
    
   angle{d}= ZN(vek(d):vek(d+1)-2,d+1) 
    meanangle(d)=mean(angle{1,d})
    stda(d)=std(angle{1,d})
    nna(d)=length(find(angle{1,d}<0))/length(angle{1,d})
npa(d)=length(find(angle{1,d}>0))/length(angle{1,d})
 nnn(d)=length(find(abs(angle{1,d})< 20))/length(angle{1,d})
end
 
%tune parameter (1.4 most successfull)
smallspeed1=length(find(s(1+1:vek(1))<1.4))/vek(1)
 for g = 1:(length(vek)-1)
speed{g}=s(vek(g)+2:vek(g+1))
     ms(g)=mean(s(vek(g)+2:vek(g+1)))
     stggg(g)=std(speed{g})
     smallspeed(g)=length(find(speed{g}<1.4))/length(speed{g})

 end;
 for t = 1:(length(vek)-1)
    Abstand(t) =  sqrt((x(vek(t+1))-x(vek(t))).^2+(y(vek(t+1))-y(vek(t)))^2)
 end;
 Abstand1=sqrt((x(vek(1))-x(1)).^2+(y(vek(1))-y(1))^2)
 
 %aggregated information
AG = [ ms1 std1 nna1 npa1 nnn1 meanangle1 stda1 Abstand1 smallspeed1; 
    ms' stggg' nna' npa' nnn' meanangle' stda' Abstand' smallspeed']; 




