0

I have an n-dimensional matrix, funtointerpolate, and I wish to perform one dimensional interpolation along one of its axes (let's call it axis m). In Python, interpolate functions such as interp1d allow one to specify the axis of interpolation. In MATLAB, I cannot see an obvious way to do this using interp1 or any other built-in interpolate functions. Ideally, the function would look something like

interpolatedfun = interp1(funtointerpolate,oldpoints,newpoints,axis = m)

An obvious way to get around this is to loop over all the other axes in funtointerpolate, but this is rather cumbersome. The motivation for interpolation is that the data in funtointerpolate is evaluated along a non-uniform grid along the m axis. I need it to be uniform along m. Mathematically, suppose I have some tensorial object

A_{ijk}

which is evaluated along a non-uniform grid along the j index. Then, I wish to find a new A such that the jth index consists of values evaluated on a uniform grid. I know the new uniform grid for the jth index, newpoints, and the old grid oldpoints.

Dev-iL
  • 23,742
  • 7
  • 57
  • 99
Physics314
  • 341
  • 1
  • 2
  • 9
  • 1
    [`interpn(oldAx1,...,oldAxM,...,oldAxN, oldAx1,...,newAxM,...,oldAxN)`](https://www.mathworks.com/help/matlab/ref/interpn.html)? – Dev-iL Dec 09 '18 at 12:28
  • Wait a second... What exactly do you mean, mathematically or geometrically, by interpolating a vector along an axis? Since the only data you have for each dimension is one value, interpolation (or extrapolation) would just return the same value, no? Would you please show what you mean using a small example with e.g. 3 or 4 dimensions? – Dev-iL Dec 09 '18 at 12:51
  • The functionality would be analogous to the `dim` argument one can pass in fft:https://www.mathworks.com/help/matlab/ref/fft.html – Physics314 Dec 09 '18 at 13:49
  • I'm very curious how you intend to perform `fft` on a single data point (because `size(funtointerpolate, anyDim) == 1)`). Perhaps you meant to write "n dimensional **matrix**" and not "n dimensional **vector**". – Dev-iL Dec 09 '18 at 13:51
  • @Dev-iL Ah yes, that is certainly a typo! Editing now. – Physics314 Dec 09 '18 at 14:03
  • Ok, great! So what about my initial suggestion, does that not work for you?(`interpn` or `griddatan`)? – Dev-iL Dec 09 '18 at 14:07
  • Yes, it works perfectly. Appreciate the help! – Physics314 Dec 09 '18 at 14:23

1 Answers1

2

You can use the interpn function for this purpose:

newV = interpn(oldAx1, ..., oldAxM, ..., oldAxN, oldV, ...
               oldAx1, ..., newAxM, ..., oldAxN);

where V is your output.

(Of course the above is pseudo-code, but it should nicely illustrate the way to solve your problem.)

Dev-iL
  • 23,742
  • 7
  • 57
  • 99