I think the question says it all. I have a coordinate pair, {x,y} and I want to extract x and y for use in further calculations. Can't find anything in the docs about this but it seems like it should be a pretty simple operation.
Asked
Active
Viewed 6,864 times
3 Answers
6
In addition to answer provided by @Kay:
One of the alternative ways to extract data would be using First and Last functions:
Example:
(*Arbitrary data*)
coord = {76, 2};
(*Process*)
First @ coord
Last @ coord
You could also extract the entire set of x and y values.
Example :
(*Arbitrary data*)
data = RandomInteger[{1, 100}, {10, 2}]
(*All 'x' values*)
data[[All, 1]]
(*All 'y' values*)
data[[All, 2]]
Reference:
Tutorial:
e.doroskevic
- 5,959
- 1
- 13
- 32
3
there is another way as well:
#1 & @@ {1, 2} (* gives 1 *)
#2 & @@ {1, 2} (* gives 2 *)
for multiple coordinates in a list:
data = RandomInteger[{1, 100}, {10, 2}]
#1 & @@@ data (* gives all x coordinates *)
#2 & @@@ data (* gives all y coordinates *)
Ali Hashmi
- 8,950
- 4
- 22
- 42