clear all clc %This code calculates speed of bacteria after results from tracking code a=csvread('results_tracking_10.csv') a4=diff(a(:,4)) c=1; cal=0.095*30; leng=length(a) leng_new=leng; pos(1)=0; b=zeros(leng,5) for i=1:length(a)-1 if a4(i)==1 pos(c+1)=i; c=c+1; end end pos(c+1)=length(a); summ=0; for i=1:a(end,4) %1 to no. of bacteria for j=pos(i)+1:pos(i+1)% from start to end index of i th bacteria s=pos(i)+1; e=pos(i+1); b(s:e,1:2)=[abs(diff(a(s:e,1:2))); 0 0]; b(s:e,3:4)=b(s:e,1:2)*cal; b(s:e,5)=(b(s:e,3).^2+b(s:e,4).^2).^(0.5); avg_sb(i)=mean(b(s:e-1,5)); end frames(i)=e-s+1 if avg_sb(i)>0 summ=summ+(e-s+1)*avg_sb(i); else leng_new=leng_new-(e-s+1); end end avg_ab=(summ/leng_new); avg_sb_col=avg_sb.' mx=max(avg_sb); mn=min(avg_sb); result=[a b]; csvwrite('analysed_data.csv',result) frames_col=frames.' frame_data=[avg_sb_col frames_col]