Sunday, January 20, 2013

procedural in mathematica

temporary variable inside a Module:

(detecs "jumps" in the list)


jump = Module[{src, dst}, src = Drop[#, 1]; dst = {Take[#, 1]};
   Do[If[Abs[Last[Last[dst]] - src[[i]]] < 2,
     dst = ReplacePart[dst,
       Length[dst] -> Append[Last[dst], src[[i]]]],
     AppendTo[dst, {src[[i]]}]], {i, 1, Length[src]}]; dst] &

No comments:

Post a Comment