二维插值:griddata和interp2
Vq
= interp2(X,Y
,V
,Xq,Yq
)
Vq
= interp2(X,Y
,V
,Xq,Yq
)
X
and Y
contain the coordinates of the sample points. V
contains the corresponding function values at each sample point. Xq
and Yq
contain the coordinates of the query points.
specifies an alternative interpolation method: 'linear'
, 'nearest'
, 'cubic'
, 'makima'
, or 'spline'
. The default method is 'linear'
also specifies Vq
= interp2(___,method
,extrapval
)extrapval
, a scalar value that is assigned to all queries that lie outside the domain of the sample points.
If you omit the extrapval
argument for queries outside the domain of the sample points, then based on the method
argument interp2
returns one of the following:
-
Extrapolated values for the
'spline'
and'makima'
methods -
NaN
values for other interpolation methods 当超出采样点的范围时,会返回NAN
Sample grid points, specified as real matrices or vectors. The sample grid points must be unique.网格采样点必须唯一
If X
and Y
are vectors, then they are treated as grid vectors. The values in both vectors must be strictly monotonic, either increasing or decreasing.当X和Y是向量时,向量的值必须严格单调
vq = griddata(x,y,v,xq,yq,method)
method
can be 'linear'
, 'nearest'
, 'natural'
, 'cubic'
, or 'v4'
. The default method is 'linear'
.
x
, y
, and v
are vectors containing scattered (nonuniform) sample points and data.
The sample points must be unique.采样点必须唯一
-
Specify arrays if you want to pass a grid of query points. Use
ndgrid
ormeshgrid
to construct the arrays. -
Specify vectors if you want to pass a collection of scattered points.
The specified query points must lie inside the convex hull of the sample data points. griddata
returns NaN
for query points outside of the convex hull.
指定的查询点必须位于样本数据点的凸包内。 griddata为凸包外部的查询点返回NaN。