I have a table of values of the form

Table[{i1,j1}, {i2,j2}...]

and I want to define a function like f[i] to take the values from the table, i.e. f[i2] = [j2] and so on. Can I do this in Mathematica?

  • 1
    $\begingroup$ You want to use Interpolation $\endgroup$ – Jason B. Oct 5 '15 at 11:28
  • $\begingroup$ You could do either this f = <|Sequence @@ Rule @@@ Table[{x[i], y[i]}, {i, n}]|> or Map[f[#[[1]]] = #[[2]] &, Table[{x[i], y[i]}, {i, n}]];. $\endgroup$ – Coolwater Oct 5 '15 at 11:28
  • 3
    $\begingroup$ It is not clear what is your Table[...]. Is it the way your create your list of pairs ? Give a more precise example. $\endgroup$ – SquareOne Oct 5 '15 at 11:34
  • 1
    $\begingroup$ f[i2]=[j2] means nothing. You did not correct your question and already accepted the first answer. I am voting to close. $\endgroup$ – SquareOne Oct 5 '15 at 12:03
table = Table[{ToExpression["i" <> ToString@n], ToExpression["j" <> ToString@n]}, {n, 5}]

$\ ${{i1, j1}, {i2, j2}, {i3, j3}, {i4, j4}, {i5, j5}}

(f[#1] = #2) & @@@ table

$\ ${j1, j2, j3, j4, j5}


enter image description here


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