0

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?

Mary
  • 788
  • 6
  • 19
  • 43
  • Not sure I understand the question? Can you give the kind of input data you want to supply (and the expected output). As it stands your code works (albeit with a warning)... – Justin May 03 '17 at 11:42
  • you can usually ignore the warning unless it says about singularity etc. Is it giving you the correct answer? In this case, it probably automatically switches to 'spline'. – Anthony May 03 '17 at 14:50

1 Answers1

1

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')
user2999345
  • 4,195
  • 1
  • 13
  • 20