0
$\begingroup$

I have the following coordinate Lists:

x={{1,2,3},{1,1,1},{2,2}} 
y={{1,2,3},{2,2,2},{1,1}} 

I want the following List:

xy={{{1,1},{2,2},{3,3}},{{1,2},{1,2},{1,2}},{{2,1},{2,1}}}

So that I could call ListPlot in the following way:

ListPlot[xy[[1]]] 

I know that I can do the following for one coordinate List but am currently failing to generalise:

xy=Transpose@{x[[1]],y[[1]]}

Thanks!

EDIT: The coordinate lists are not of equal length.

$\endgroup$
3
  • $\begingroup$ Try Transpose[{x, y}, {1, 3, 2}]. $\endgroup$ Commented Apr 5, 2017 at 10:17
  • $\begingroup$ @J.M. I edited my post. Your solution only works if all Lists are of the same length $\endgroup$
    – MaxJ
    Commented Apr 5, 2017 at 10:25
  • 2
    $\begingroup$ Then, try Flatten[{x, y}, {{2}, {3}}]. $\endgroup$ Commented Apr 5, 2017 at 10:45

1 Answer 1

1
$\begingroup$
MapThread[Transpose@*List, {x, y}]
{{{1, 1}, {2, 2}, {3, 3}}, {{1, 2}, {1, 2}, {1, 2}}, {{2, 1}, {2, 1}}}
$\endgroup$

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.