1
$\begingroup$

I have a table

 {{0., 0., 0.}, {0.002, 0.08942, -0.08942}, {0.008, 
  0.233889, -0.178706}, {0.018, 0.366918, -0.267724}, {0.031, 
  0.496136, -0.350769}, {0.049, 0.639568, -0.439999}, {0.07, 
  0.779356, -0.5245}, {0.095, 0.922931, -0.609077}, {0.124, 
  1.06945, -0.693271}, {0.156, 1.21404, -0.77438}, {0.191, 
  1.35745, -0.852947}, {0.229, 1.50013, -0.929279}, {0.271, 
  1.64566, -1.00987}}

and I want to find the right element in the table. For example each row has three columns and I want to specify the value in the first column while the program should return the other two. Example: If I insert value 0.049 this is element {0.049, 0.639568, -0.439999} in the table and I want the computer to return me values 0.639568 and -0.439999.

Can this be done?

$\endgroup$
  • 2
    $\begingroup$ Try Cases[data,{0.049,a__}]:>a] $\endgroup$ – kale Jul 13 '15 at 13:55
  • $\begingroup$ Works! Thank you! $\endgroup$ – skrat Jul 13 '15 at 13:57
  • $\begingroup$ Is it possible to extend this "Cases" to this: After he finds the element (in this case {0.049, 0.639568, -0.439999}) I want to get out let's say 0.639568 but I don't want to copy that number. Something like [[2]] but I don't know where to put it... ? $\endgroup$ – skrat Jul 13 '15 at 14:06
  • $\begingroup$ @kale or skrat, maybe you can answer the question now? $\endgroup$ – J. M. will be back soon Jul 13 '15 at 14:07
1
$\begingroup$

This is an alternate method, but I rather prefer kale's:

FindCol[t_, n_, col_] := t[[Position [t, n][[1, 1]], col]]
FindCol[data, 0.049, 3]

(* -0.439999 *)
$\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.