I have a set of data that looks vaguely like this:

data = {{{a,x1,y1,a},{a,x1,y1,a},{a,x1,y1,a},{a,x1,y1,a},{a,x1,y1,a}},

where the quantities I am interested in are the x and y values and the a, b, c are simply identifiers I don't need anymore.

I was attempting to extract those values and put them into a new set called positions that then looks like:

positions = {{{x1,y1},{x1,y1},{x1,y1},{x1,y1},{x1,y1}},

using a double table structure:

  positions = Table[{data[[1]][[i]][[2]], data[[1]][[i]][[3]]}, {j, 1, Length[data]}, {i, 1, Length[data[[j]]]}]

but it hasn't worked. I believe my problem is just where I have placed / how I have used the iterators. I was wondering if anyone could show me where I have gone wrong? Thanks!


2 Answers 2


You can write positions = data[[All, All, {2, 3}]], or by adjusting your code:

positions = Table[{data[[j]][[i]][[2]], data[[j]][[i]][[3]]},
              {j, 1, Length[data]}, {i, 1, Length[data[[j]]]}]

try Part:

data[[All, All, {2, 3}]]

{{{x1, y1}, {x1, y1}, {x1, y1}, {x1, y1}, {x1, y1}}, {{x2, y2}, {x2, y2}, {x2, y2}}, {{x3, y3}, {x3, y3}, {x3, y3}, {x3, y3}}}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.