function [p, msd] = calcMSD2(path, L, min_dt, max_dt, dt)

msd = [];
path = path(:,1:2);
dt = dt*0.001;

if L == 1
    L = length(path(:, 1));
end

tvec = dt:dt:100*dt;

path = path(1:L,:);

for i=min_dt:max_dt
    msd(i) = mean(sum((path(i+1:end,:)-path(1:end-i,:)).^2,2));
end

p = tvec(min_dt:max_dt)'\(msd(min_dt:max_dt)');% - (4*0.025^2));

%p = polyfit(tvec(min_dt:max_dt),msd(min_dt:max_dt),1); p = p(1);

