Message Boards Message Boards


{2} in Position output instead of the number 2

Posted 9 years ago
3 Replies
3 Total Likes

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.

POSTED BY: Christian Rafael
3 Replies
Posted 9 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]


{a, b, a, a, b, c, b}[[First[p]]]
POSTED BY: Jaebum Jung

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.


This is effectively the same code as posted above.

POSTED BY: Sean Clarke
Posted 9 years ago

One way is the following:

x = {2}
POSTED BY: Jim Baldwin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract