%To calculate the mean square displacement (MSD) as a function of elapsed time based on displacement data %Input displacement data as a 1D array displacement = ; %Input the time interval of time-lapse imaging t = ; %Get the number of data points N = length(displacement); %Initialize variables timeLapse(N-1) = 0; msd(N-1) = 0; result(1:N-1,2) = 0; %Go through each time point for n = 1:N-1 %Reinitialize the variable to zero for every time point msdSum = 0; %Calculate MSD for the current time point for j = 1:N-n msdTemp = (displacement(j+n) - displacement(j))^2; msdSum = msdSum + msdTemp; end msd(n) = msdSum/(N-n); %Calculate the elapsed time timeLapse(n) = t*n; end result(:,1) = timeLapse'; result(:,2) = msd';