I have a 4 dimensional array. I can use interpn in Matlab to construct interpolated points between the array values. However, this command only returns the interpolated values at specified points. Is there a way to directly obtain a full function of interpolated points as an output, which I can then evaluate at any point?
Asked
Active
Viewed 95 times
0
-
When you use interpn, you can get the interpolated values at multiple points with a single call, is that what you want to do? Are you asking about curve fitting to get the parameters for a function? – Kenneth Boyd Jan 02 '21 at 14:46
-
@KennethBoyd It would be convenient to get a function, which I can then call at different points of a loop. Yes in practice this would be storing the parameters from curve fitting. This way it does not need to perform the whole interpolation again several times. – fes Jan 02 '21 at 14:55
-
If you're data is noisy and you know what the function should look like, then a curve fit makes sense. But if noise is not an issue and you don't know what function to fit, using interpn multiple times may be faster. Interpolating can be very fast compared to curve fitting unless the fit is very simple. – Kenneth Boyd Jan 02 '21 at 14:59
-
1These interpolation methods are piecewise, meaning that the function definition is different in every tile. The functions are bivariate polynomials of some degree. I don't think that implementing this as a function would be helpful. – Jan 04 '21 at 20:25
1 Answers
0
Short answer: No.
A slightly longer answer:
There are the workarounds, where you define a function on top of the interpn
, although this will require the recalculation of the interpolation.
e.g.
p = [1 2 3 4 5];
v = [12 16 31 10 6];
f = @(x) interpn(p,v,x,'cubic');
If you want to avoid recalculating the interpolation for new points would require the interpolation to be parametric, which it is not the necessarily the case, e.g. if you use "nearest" as interpolation method. Depending on the type of interpolation you are using (assuming that it is parametric), there might be a different function more suitable.

Nicky Mattsson
- 3,052
- 12
- 28
-
Nice one, I would also suggest existing [griddedInterpolant](https://fr.mathworks.com/help/matlab/ref/griddedinterpolant.html) or [scatteredInterpolant](https://fr.mathworks.com/help/matlab/ref/scatteredinterpolant.html) classes to precompute things(or get inspired to create custom class for precomputing and storing things (gradients, etc....) useful for some specific interpolation method of your own. – CitizenInsane Jan 06 '21 at 17:12