Matlab interp2 extrapolation

前端 未结 2 419
眼角桃花
眼角桃花 2021-01-28 15:16

I am doing a 2-D interpolation using interp2. For some data values, the interp2 command returns NaN because one of the dimensions are outside of the range defined b

2条回答
  •  忘掉有多难
    2021-01-28 16:03

    Yes, there are two ways to get interp2 to return a meaningful value out of bounds according to the docs.

    1. Use the 'spline' interpolation method. Unlike option #2, this will actually extrapolate the data based on the boundary conditions of the spline.
    2. Specify a final extrapval parameter. This constant will be returned instead of NaN for all other interpolation methods.

    Unfortunately, there does not appear to be a way to specify something like "nearest neighbor on the grid" or something like that. If the out-of bounds elements are close to the edges, perhaps you could just expand the input array. For example like this:

    x = [x(1, 1), x(1, :), x(1, end); ...
         x(:, 1), x, x(:, end); ...
         x(end, 1), x(end, :), x(end, end)]
    

提交回复
热议问题