After integrating a toral differential equation I get as trajectory coordinates, the vectors x,y, and then calculate:
xt = mod2pi.(x)
yt = mod2pi.(y)
I want to insert a NaN between two consecutive elements of xt and yt, with the property that the left one is almost 2π, and the right one, almost 0.
How to detect such a jump?
Example:

I don’t quite understand your question, but I’ll take a shot. It’s not as efficient as possible, but I’m guessing this is for plotting so it that doesn’t matter.

function insertnanwheredecreases!(z)
i = firstindex(z)+1
while checkbounds(Bool, z, i)
if z[i-1] > z[i] # decrease from index i-1 to i
insert!(z, i, NaN)
i += 1 # skip the new NaN
end
i += 1
end
return z
end
insertnanwheredecreases!(xt)

If you want some behavior based on bothxt and yt then you’ll need to modify this function a bit. I might have missed some corner cases in what I wrote.