2

I have a problem in which I have to interpolate 4D data d = f(a, b, c) often, because the interpolation happens within an optimisation routine. Now, at first I programmed this using Matlab's interpn function. However, the program obviously became very slow, because the cubic splines had to be constructed upon each iteration within the optimisation.

I have read about 2D spline interpolation and I am basically looking for its 4D equivalent: pp = spline(a,b,c,d). Also, I found the scatteredInterpolant function (I have a non-uniform grid), but this function only gives me options for 'linear', 'nearest', or 'natural' and not the 'spline' option I'm looking for.

I could imagine that Matlab would have the function that is underneath the interpn function available, but I can't seem to find it. Does anyone know such a function that returns the piecewise polynomial or some other form of a spline function for a 4D interpolant, preferably Matlab-original?

P.s. I have also looked into a workaround; typing edit interpn, I have tried copying the Matlab function interpn, naming it differently and editing it such that it returns F instead of Vq, the interpolating function. However, doing this it says it doesn't recognise the methodandextrapval function, the first nested Matlab built-in it encounters.

Sam
  • 305
  • 1
  • 8
  • 1
    The focus of this question is how to perform said operation _efficiently_, though strangely it is not tagged with [tag:performance] etc. A [recent post](https://blogs.mathworks.com/pick/2019/11/22/interpolation-utilities/) in the blog "File Exchange Pick of the Week" referred to the [Interpolation Utilities](https://www.mathworks.com/matlabcentral/fileexchange/36800) submission. I haven't checked if there are N-D methods covered there, but perhaps it's a good place to start. If you're planning to implement it yourself, I would check the source codes of scipy/numpy/octave for ideas. – Dev-iL Nov 24 '19 at 08:04
  • Thanks for the suggestion about the interpolation utilities submission. I'll definitely check that out. On a different note, the focus of this question clearly _isn't_ about performance; performance is just an introduction to the relevance of the problem. Although my problem arises from a need to increase performance, the question's focus is clearly on 4D spline interpolation. – Sam Dec 03 '19 at 11:55
  • If your post is not mainly about performance - I don't understand the reason for your discontent with `interpn`. Is it not doing spline interpolation (but rather using some method you find too coarse or inaccurate)? Is it only too slow? Is it because you want to get the equations of the underlying splines, but MATLAB doesn't output them? I think it would be a good idea to restructure the post a bit so that the main issue is clearer (... and we don't have to infer it). Perhaps it's also worth mentioning why you want these splines, as there may be a better way to get the same result. – Dev-iL Dec 03 '19 at 12:05
  • 1
    As I state in my previous post, the problem indeed _arises_ from performance considerations. `interpn` is indeed too slow for my liking, when called upon in an iterative loop of some sort. However, I have already identified and found a solution to this performance issue: constructing the interpolating function/splines once, beforehand. This works for linear/neighbour/natural interpolation functions, but not for spline interpolation. The focus of my question thus is: how do I find the 4D equivalent of Matlab's 2D spline interpolation. – Sam Dec 03 '19 at 12:46
  • interpolation cubics like CATMULL-ROM is the answer ... no fitting just use the input points directly... – Spektre Jul 08 '20 at 11:08

0 Answers0