function [p1, p2] = calcMSD3(path, L, min_dt, max_dt, dt)

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

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

tvec = dT:dT:100*dT;
path(2:end,:) - path(1:end-1,:) ;
%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)';

p2 = polyfit(tvec(min_dt:max_dt),msd(min_dt:max_dt),2);
p2 = polyfit([3.5000,    7.0000,   10.5000],msd(min_dt:max_dt),2);

figure(11), plot(min_dt:max_dt, msd(min_dt:max_dt))
ylim([0, 0.05])
% figure(12), plot(path(:, 1)/0.075, path(:, 2)/0.075, '-o')
% axis equal


fun = @(p,a) abs(p(3)) + abs(p(2))*a + abs(p(1))*a.^2;

% msd = 7 + (min_dt:max_dt)*5 -2*((min_dt:max_dt).^2)

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

%lsqcurvefit(fun,[0.001,0.001,0.001],tvec(min_dt:max_dt),msd)


% polyfit(min_dt:max_dt,msd, 1)
