%Function gets indices by imposing periodic boundary conditions function n = ndx(k,L) n=k; if k>L n=mod(k,L); elseif k<1 n=k+L; end