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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…