title: Mean-Squared Displacement (MATLAB)
body: <p>Please can you help me understand how to calculate the Mean-Squared Displacement for a single particle moving randomly within a given period of time. I have read a lot of articles on this (including Saxton,1991,Single-Particle Tracking: The Distribution of Diffusion Coefficients), but still confused (not getting the right answer).</p>
  
  <p>Let me start by showing you how I do it and please correct me if I'm wrong:
  The way I'm doing it is as follows:<br>
  1.Run the program from t=0 to t=100<br>
  2.Calculate the displacement, (s(t)-s(t+tau)), at each timestep (ie. at t=1,2,3,...100) and store it in a vector<br>
  3.Square the answer to number 2<br>
  4.find the mean to the answer of 3    </p>
  
  <p>In essence, this is what I'm doing in Matlab    </p>
  
  <p>%Initialise the lattice with a square consisting of 16 nonzero lattice sites then proceed %as follows to calculate the MSD:</p>
  
  <pre><code>for t=1:tend    
  % Allow the particle to move randomly in the lattice. Then do the following    
  [row,col]=find(lattice&gt;0);    
  centroid=mean([row col]);    
  xvec=[xvec centroid(2)];    
  yvec=[yvec centroid(1)];    
  
  k=length(xvec)-1;  % Time    
  dt=1;       
  diffx = xvec(1:k) - xvec((1+dt):(k+dt));    
  diffy = yvec(1:k) - yvec((1+dt):(k+dt));    
  
  xsquare = diffx.^2;    
  ysquare = diffy.^2;    
  MSD=mean(xsquare+ysquare);    
  end
  </code></pre>
  
  <p>I'm trying to find the MSD in order to compute the diffusion co-efficient. Note that I'm modelling a collection of lattice sites (16) to represent a single particle (more biologically realistic), instead of just one. I have been brief with the comment within the for loop as it is quite long, but I'm happy to send it to you.   </p>
  
  <p>So far, I'm getting very small MSD values  (in the range of 0.001-1), whereas I'm supposed to get values in the range of (10-50). The particle moves very large distances so surely my range of 0.001-1 cannot be right! </p>
  
  <hr>
  
  <p>This is an extract from the article which I'm trying to reproduce their figure:    </p>
  
  <p>" We began by running some simulations in 1D for a single
  cell. We allowed the cell to move for a given number of
  Monte Carlo time steps (MCS), worked out the mean square
  distance traveled in that time, repeated this process 500
  times, and evaluate the mean squared distance  for this t.
  We then repeated this process ten times to get the mean of
  . The reason for this choice of repetitions was to
  keep the time required to run the simulations within a reasonable
  level yet ensuring that the standard deviation of the
  mean was relatively small (&lt;7%)".<br>
  You can access the article here "From discrete to a continuous model of biological cell movement, 2004, by Turner et al., Physical Review E".</p>
  
  <hr>
  
  <p>Any hints are greatly appreciated.</p>