% calculate FMI = <d_y>/<L> 
clearvars;
currentdir=pwd;
addpath(currentdir);
[FileName,PathName] = uigetfile('*.xlsx');
cd(PathName);
data=xlsread(FileName);
n=1;
trackid=data(n,4);
total_dist=0;
xs=data(n,6);
ys=data(n,7);
ntrack=0;
while n<size(data,1)
    n=n+1;
    if ~(data(n,4)==trackid)
        ntrack=ntrack+1;
        D(ntrack,2)=-(data(n-1,7)-ys)/total_dist;
        D(ntrack,1)=trackid;
        total_dist=0;
        trackid=data(n,4);
        xs=data(n,6);
        ys=data(n,7);
    else
        total_dist=total_dist+sqrt((data(n-1,6)-data(n,6))^2+(data(n-1,7)-data(n,7))^2);
    end
end
ntrack=ntrack+1;
D(ntrack,2)=sqrt((data(n,6)-xs)^2+(data(n,7)-ys)^2)/total_dist;
D(ntrack,1)=data(n,4);
xlswrite([FileName(1:end-5) '_D.xlsx'],D);
cd(currentdir);    