4
$\begingroup$

Suppose I have a table, u, which is created as follows:

 u = {};
 u1 = Table[678, {y, 1, 10}];
 u2 = Table[1888, {y, 1, 10}]; 
 u = AppendTo[u, Thread[{1, u1}]];
 u = AppendTo[u, Thread[{2, u2}]];

It is essentially an x-y grid of values where, for example, x1 = 1 (the x-coordinate at point 1) and x2 = 2. Furthermore, we then have vertical "profiles" of y-values lying "on top" of each x-coordinate, where at x1 = 1 we have the value 678 from y = 1 to y = 10, and at x2 = 2 we have the value 1888 from y = 1 to y = 10:

{{{1, 678}, {1, 678}, {1, 678}, {1, 678}, {1, 678}, {1, 678},
{1, 678}, {1, 678}, {1, 678}, {1, 678}}, {{2, 1888}, {2, 1888},
{2, 1888}, {2, 1888}, {2, 1888}, {2, 1888}, {2, 1888}, {2, 1888},
{2, 1888}, {2, 1888}}}

and u[[1]] is the following:

{{1, 678}, {1, 678}, {1, 678}, {1, 678}, {1, 678}, {1, 678},
{1, 678}, {1, 678}, {1, 678}, {1, 678}}

Now, what I'm hoping to do is at x1 = 1, select all the y-values from y = 1 to y = 10 into a single table, where I'll just have

{678, 678, 678, 678, 678, 678, 678, 678, 678, 678}

Does anyone know how I might do this? Thanks

$\endgroup$
1
  • 1
    $\begingroup$ Try Cases[u, {1, x_} :> x, -1] $\endgroup$
    – eldo
    Oct 26, 2014 at 13:40

2 Answers 2

5
$\begingroup$
u[[1, All, 2]]
(* {678, 678, 678, 678, 678, 678, 678, 678, 678, 678} *)

u[[2, All, 2]]
(* {1888, 1888, 1888, 1888, 1888, 1888, 1888, 1888, 1888, 1888} *)
$\endgroup$
2
  • $\begingroup$ Thanks very much kguler, worked like a charm. $\endgroup$ Oct 26, 2014 at 14:16
  • $\begingroup$ @user7388, my pleasure. Thank you for the Accept. $\endgroup$
    – kglr
    Oct 26, 2014 at 14:17
1
$\begingroup$
mat = {{{1, 678}, {1, 678}, {1, 678}, {1, 678}}, {{2, 1888}, {2, 1888}, {2, 1888}, {2, 1888}}};

res = Rule @@@ Catenate @ mat // Merge[Identity]

enter image description here

res[2]

enter image description here

$\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.