To create a table and an interpolation function of 3D data T=f(X,Y) I have the answer here: interpolation of 3D data

How to create a table/interpolation function of 4D data T=f(X,Y,R)?

If I do

dada = Flatten[Table[{x, r, t, func[x, r, t]}, {x, 0, 1}, {r, 0, 0.12}, {t, 0, 
 1}], 1];

doesn't work. func[x,r,t] is a valid function for this domain. I think it has to do with Flatten.

  • 1
    $\begingroup$ You need learn about Interpolation $\endgroup$
    – Apple
    Aug 26, 2014 at 14:22
  • $\begingroup$ In the same way; add a R component to your Table. $\endgroup$
    – user21
    Aug 26, 2014 at 14:22
  • $\begingroup$ This doesn't work. $\endgroup$ Aug 26, 2014 at 14:57

1 Answer 1


An example interpolation of 4D data:

Interpolation[Join[#, {RandomReal[]}] & /@ Tuples[Range@10, 3]]

For Interpolation to treat the indexing as regular the indices must be in ascending order, with the right-hand side iterating first (e.g. {1,1,1}, {1,1,2}, {1,1,3}). Note that Tuples is automatically in the right order if the provided array is in the right order.

Edit: Your code is almost correct, except that you should Flatten to the second level, not the first. Also by default Table will use "1" as its step-size, you need to specify the step-size if the step is going to be different from 1. Note that Interpolation will throw a warning about reducing the order because you only have 2 points per dimension.

data = Flatten[Table[{{x, r, t}, RandomReal[]},
               {x, 0, 1}, {r, 0, 0.12, 0.12}, {t, 0, 1}], 2];
intfunc = Interpolation@data;

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.