I have a nested list of time and position for multiple particles over multiple time steps. I want to cut all the time steps off (for each particle) after which the $z$ coordinate goes above a certain value $zmax$.
So far I've been using the TakeWhile
function but that only returns the $z$ values, not the entire list.
Is there a way to get around this?
The structure of the list is
{
{{t1(0), x1(0), z1(0)}, ..., {t1(n), x1(n), z1(n)}},
{{t2(0), x2(0), z2(0)}, ..., {t2(n), x2(n), z2(n)}},
{{}, ..., {tn(n), xn(n), zn(n)}}
}
where the number after the letter is the particle number, and the one in brackets is the time step. If that helps!
For 2 particle example:
Data = {{{0,0,0},{1,10,10},{2,20,20}},{{0,0,0},{1,15,15},{2,30,30}}}.
Setting the zmax
to be 20 for example. Code used:
TakeWhile[Data[[1, All, 3]], # < 40 &]
Which gives: {0,10}. This is only for the first particle, so I presume I'd use some sort of iterative process to do it for all, but I mostly want the output to be {{0,0,0},{1,10,10}} so that every field is displayed.
TakeWhile[]
? $\endgroup$Map[Function[particle, TakeWhile[particle, Last[#] < zmax &]], yournestedlist]
(alternativelyTakeWhile[#, Last[#] < zmax &] & /@ yournestedlist
)? $\endgroup$