1
$\begingroup$

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}},
{{b,x2,y2,b},{b,x2,y2,b},{b,x2,y2,b}},
{{c,x3,y3,c},{c,x3,y3,c},{c,x3,y3,c},{c,x3,y3,c}}}

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}},
{{x2,y2},{x2,y2},{x2,y2}},
{{x3,y3},{x3,y3},{x3,y3},{x3,y3}}}

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!

$\endgroup$
1
$\begingroup$

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]]]}]
$\endgroup$
2
$\begingroup$

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}}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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