matlabinterpolationcubicspatial-interpolationbicubic

Cubic interpolation for specific points using interp2 in Matlab


Given the following example is there a way to achieve bicubic interpolation without generating an entire finely-spaced grid?:

    years = [5,10,20,25,40];
    service = 1:3;
wage = [50 99 787.685
          779 795 850
          803 779 388
          886 753 486
          849 780 598];
    w = interp2(service,years,wage,1.5,37.5,'cubic')

Warning: The 'cubic' method requires the grid to have a uniform spacing. Switching the method from 'cubic' to 'spline' because this condition is not met.

I understand the reason for the warning. So wish to find a solution by specifying particular points without having to generate an entire equally spaced surface (the data available is not equally spaced). Does not necessarily have to be interp2. I will have to run this for hundreds of surfaces and hundreds of query points so would need to be quite fast at returning "w". Any ideas?


Solution

  • If you insist on using 'cubic' interpolation method you can use griddata which is designated for interpolating scattered data, i.e. data which is not defined on uniform spaced grid:

    years = [5,10,20,25,40];
    service = 1:3;
    wage = [50 99 787.685
        779 795 850
        803 779 388
        886 753 486
        849 780 598];
    w = griddata(service,years,wage,1.5,37.5,'cubic')