0
|
6052 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
GROUPS:

# {2} in Position output instead of the number 2

Posted 10 years ago
 Hi, I'm using the Position function to get the position of a number in a matrix, but it prints it as {2} instead of 2 and I can't use it for an index later... how can i switch it to 2 without the {}?? Please help.
3 Replies
Sort By:
Posted 10 years ago
 The Position function returns a List of positions. This is because an element might be found in multiple locations on a list. Position is very often used with First or Last to get the first or last element out of a list. First[Position[....]] This is effectively the same code as posted above.
Posted 10 years ago
 One way is the following: x = {2} x[[1]] 
Posted 10 years ago
 Like Sean mentioned you can use First[Position[...]] or FirstPosition[...] to get the first position of what you look for.To get element from result, you could do: p = FirstPosition[{a, b, a, a, b, c, b}, b] Extract[{a, b, a, a, b, c, b}, p] or {a, b, a, a, b, c, b}[[First[p]]]