Let's say I have the following list:
L = {2,4,6,8,10}
How can I get Mathematica to find the index position of the first value in the list that is over 4 (6 in this case). I tried Position[L, L > 4]
, but this gave no output. Any help would be appreciated.
Answer
In version 10 there is a new function FirstPosition
:
L = {2, 4, 6, 8, 10};
FirstPosition[ L, x_ /; x > 4]
{3}
The second argument of Position
as welll as of FirstPosition
is a pattern, so this would yield what you seemed to expect:
Position[ L, x_ /; x > 4]
{{3}, {4}, {5}}
Comments
Post a Comment