File Exchange

image thumbnail

Kehl, a fast (no loop) method to compute MSD

version 1.1 (2.01 KB) by

Kehl computes the mean squared displacements (MSD), with no loop. Fully vectorized code.

1 Download

Updated

View License

MSD is a measure of the displacement over a certain interval of time, used for instance to analyze trajectories and tell if it's ballistic, diffusive, sub-diffusive, etc.
To compute MSD, all the possible time intervals within the trajectory need to be considerer. The simplest way uses nested loops :
the first loop runs over the time points, the other loop runs over the possible interval from each time point.

Thoses nested loops are a nightmare for fast computation, especially for long trajectories.

Kehl suppresses the loops, and computes all the squared distance at once, then sorts and averages them out.

Comments and Ratings (1)

A B

A B (view profile)

Nice work. Could maybe be improved by initializing NaN-Arrays instead of 0-s so nothing hast be be pruned prior to the actual calculation.

Updates

1.1

A mispelling in a comment

MATLAB Release
MATLAB 7.11 (R2010b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video