Matlab code for length scale analysis