scattered data interpolation

拜拜、爱过 提交于 2019-11-28 04:27:17

问题


I have a set of data for example:

X Y Z

1 3 7

2 5 8

1 4 9

3 6 10

I would like to interpolate Z for X=2.5 and Y=3.5 . How do i do it? I cannot use interp2 here because X and Y are not strictly monotonic (increasing or decreasing).


回答1:


It seems like griddata is the function you are looking for:

z = griddata( [1 2 1 3], [3 5 4 6], [7 8 9 10], 2.5, 3.5, 'nearest' )



回答2:


The currently preferred way to perform scattered data interpolation is via the scatteredInterpolant object class:

>> F = scatteredInterpolant([1 2 1 3].',[3 5 4 6].',[7 8 9 10].','linear') %'
F = 
  scatteredInterpolant with properties:

                 Points: [4x2 double]
                 Values: [4x1 double]
                 Method: 'linear'
    ExtrapolationMethod: 'linear'
>> Zi = F(2.5,3.5)
Zi =
    6.7910

Alternate syntax,

>> P = [1 3 7; 2 5 8; 1 4 9; 3 6 10];
>> F = scatteredInterpolant(P(:,1:2),P(:,3),'linear')

For the advantages of scatteredInterpolant over griddata see this MathWorks page on Interpolating Scattered Data. In addition to syntactic differences, two main advantages are extrapolation and natural-neighbor interpolation. If you want to interpolate new data with the same interpolant, then you also have the performance advantage of reusing the triangulation computed when the interpolant object is created.



来源:https://stackoverflow.com/questions/21275574/scattered-data-interpolation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!