Documentation

scatteredInterpolant

Interpolate 2-D or 3-D scattered data

Description

UsescatteredInterpolant在2-D或3-D数据集上执行插值scattered datascatteredInterpolantreturns theinterpolantF对于给定的数据集。你可以评估Fat a set of query points, such as(XQ,YQ)in 2-D, to produce interpolated valuesVQ = F(XQ,YQ)

UsegriddedInterpolant执行插值gridded data

创建

Description

F= scatteredInterpolantcreates an empty scattered data interpolant object.

example

F= scatteredInterpolant(XG.ydF4y2Ba,yg.ydF4y2Ba,v)创建一个符合表格表面的插值v=F(XG.ydF4y2Ba,yg.ydF4y2Ba).vectors.XG.ydF4y2Bayg.ydF4y2Baspecify the(x,y)coordinates of the sample points.vis a vector that contains the sample values associated with the points(x,y)

example

F= scatteredInterpolant(XG.ydF4y2Ba,yg.ydF4y2Ba,z,v)creates a 3-D interpolant of the formv=F(XG.ydF4y2Ba,yg.ydF4y2Ba,z).

example

F= scatteredInterpolant(P,v)指定样本点作为数组的坐标。行的行P包含(XG.ydF4y2Ba,yg.ydF4y2Ba) or (XG.ydF4y2Ba,yg.ydF4y2Ba,z)坐标的值v

example

F= scatteredInterpolant(___,Method)specifies an interpolation method:'nearest','线性', 要么'natural'.SpecifyMethodas the last input argument in any of the first three syntaxes.

example

F= scatteredInterpolant(___,Method,ExtrapolationMethod)specifies both the interpolation and extrapolation methods. PassMethodExtrapolationMethodtogether as the last two input arguments in any of the first three syntaxes.

  • Methodcan be:'nearest','线性', 要么'natural'

  • ExtrapolationMethodcan be:'nearest','线性', 要么'none'

Input Arguments

全部展开

样本点,指定为与相同尺寸的载体v.样本点应该是唯一的。但是,如果样本点包含重复项,scatteredInterpolantdisplays a warning and merges the duplicates into a single point.

数据类型:double

样本点数组, specified as anm-by-nmatrix, wheremis the number of points andn是点居住的空间的尺寸。每一排P包含(XG.ydF4y2Ba,yg.ydF4y2Ba) or (XG.ydF4y2Ba,yg.ydF4y2Ba,z)样本点的坐标。样本点应该是唯一的。但是,如果样本点包含重复项,scatteredInterpolantdisplays a warning and merges the duplicates into a single point.

数据类型:double

示例值,指定为定义样本点处的函数值的向量,v=F(XG.ydF4y2Ba,yg.ydF4y2Ba,z)

数据类型:double

Interpolation method, specified as one of these options.

Method Description 连续性
'线性'(default)

Linear interpolation

C0
'nearest'

Nearest neighbor interpolation

不连续
'natural'

Natural neighbor interpolation

C1(except at sample points)

推断方法,指定为其中一个选项。

ExtrapolationMethod Description
'线性'

Linear extrapolation based on boundary gradients. Default whenMethodis'线性'要么'natural'

'nearest'

Nearest neighbor extrapolation. This method evaluates to the value of the nearest neighbor on the boundary. Default whenMethodis'nearest'

'none'

没有推断。凸壳外的任何疑问PointsreturnNaN

特性

全部展开

样本点,指定为矩阵。矩阵的大小是m-by-2要么m-by-3to representmpoints in 2-D or 3-D space. Each row ofPoints包含(XG.ydF4y2Ba,yg.ydF4y2Ba) or (XG.ydF4y2Ba,yg.ydF4y2Ba,z)独特样本点的坐标。行in.Pointscorrespond to the function values inValues

数据类型:double

Function values at sample points, specified as a vector of values associated with each point inPoints

数据类型:double

Interpolation method, specified as'线性','nearest', 要么'natural'.SeeMethodfor descriptions of these methods.

外推方法, specified as'nearest','线性', 要么'none'.SeeExtrapolationMethodfor descriptions of these methods.

数据类型:double

Usage

UsescatteredInterpolantto create theinterpolant,F.Then you can evaluateF在使用以下任何语法中的特定点:

Vq = F(Pq)
Vq = F(Xq,Yq)
Vq = F(Xq,Yq,Zq)
Vq = F({xq,yq})
Vq = f({xq,yq,zq})

  • Vq = F(Pq)specifies the query points in the matrixPQ..每一行PQ.contains the coordinates of a query point.

  • Vq = F(Xq,Yq)Vq = F(Xq,Yq,Zq)将查询点指定为2或三个相同大小的矩阵。

  • Vq = F({xq,yq})Vq = f({xq,yq,zq})指定查询点作为grid vectors.Use this syntax to conserve memory when you want to query a large grid of points.

Examples

collapse all

定义一些采样点并计算这些位置的三角函数的值。这些点是插值的样本值。

t = linspace(3/4 * pi,2 * pi,50)';x = [3 * cos(t);2 * cos(t);0.7 * cos(t)];Y = [3 * SIN(T);2 * SIN(T);0.7 * sin(t)];v = Repelem([ -  0.5; 1.5; 2],长度(t));

Create the interpolant.

f =散射interpolant(x,y,v);

评估查询位置的插值(XQ.,yq).

TQ = LINSPACE(3/4 * PI + 0.2,2 * PI-0.2,40)';xq = [2.8 * cos(tq);1.7 * cos(tq);cos(tq)];YQ = [2.8 * SIN(TQ);1.7 * SIN(TQ);罪(TQ)];VQ = F(XQ,YQ);

绘制结果。

plot3(x,y,v,'.',xq,yq,vq,'.'), 网格title('线性插值')Xlabel('x'), ylabel('y'), zlabel('Values') 传奇('样本数据','插值查询数据','地点','Best')

Create an interpolant for a set of scattered sample points, then evaluate the interpolant at a set of 3-D query points.

定义200个随机点并采样三角函数。这些点是插值的样本值。

P = -2.5 + 5*gallery('uniformdata',[200 3],0); v = sin(P(:,1).^2 + P(:,2).^2 + P(:,3).^2)./(P(:,1).^2+P(:,2).^2+P(:,3).^2);

Create the interpolant.

f =散射interpolant(p,v);

评估查询位置的插值(XQ.,yq,zq).

[xq,yq,zq] = meshgrid(-2:0.25:2); vq = F(xq,yq,zq);

绘图切片结果。

xslice = [-.5,1,2];yslice = [0,2];zslice = [-2,0];切片(XQ,YQ,ZQ,VQ,XSLICE,YSLICE,ZSLICE)

替换该元素Values您希望在采样点处更改值时的属性。当您评估新的Interpolant时,您可以立即获得结果,因为原始三角测量不会改变。

Create 50 random points and sample an exponential function. These points are the sample values for the interpolant.

x = -2.5 + 5*gallery('uniformdata',[50 1],0);y = -2.5 + 5 *图库('uniformdata',[50 1],1); v = x.*exp(-x.^2-y.^2);

Create the interpolant.

f =散射interpolant(x,y,v)
f =散射interpolant.with properties: Points: [50x2 double] Values: [50x1 double] Method: 'linear' ExtrapolationMethod: 'linear'

Evaluate the interpolant at(1.40,1.90)

F(1.40,1.90)
ans = 0.0029

Change the interpolant sample values and reevaluate the interpolant at the same point.

vnew = x。^ 2 + y。^ 2;F.Values = VNew;F(1.40,1.90)
ans = 6.1109

比较提供的几种不同插值算法的结果scatteredInterpolant

创建50个分散点的示例数据集。点数是人为小的,以突出插值方法之间的差异。

x = -3 + 6*rand(50,1); y = -3 + 6*rand(50,1); v = sin(x).^4 .* cos(y);

创建插值和查询点网格。

f =散射interpolant(x,y,v);[xq,yq] = meshgrid(-3:0.1:3);

Plot the results using the'nearest','线性', and'natural'methods. Each time the interpolation method changes, you need to requery the interpolant to get the updated results.

F.Method ='nearest';vq1 = F(xq,yq); plot3(x,y,v,'mo') 抓住mesh(xq,yq,vq1) title('Nearest Neighbor') 传奇('Sample Points','内插表面','地点','西北')

F.Method ='线性';vq2 = F(xq,yq); figure plot3(x,y,v,'mo') 抓住mesh(xq,yq,vq2) title('线性') 传奇('Sample Points','内插表面','地点','西北')

F.Method ='natural';vq3 = F(xq,yq); figure plot3(x,y,v,'mo') 抓住网格(XQ,YQ,VQ3)标题('Natural Neighbor') 传奇('Sample Points','内插表面','地点','西北')

绘制确切的解决方案。

figure plot3(x,y,v,'mo') 抓住网格(xq,yq,sin(xq)。^ 4。* cos(yq))标题('Exact Solution') 传奇('Sample Points','Exact Surface','地点','西北')

Query an interpolant at a single point outside the convex hull using nearest neighbor extrapolation.

Define a matrix of 200 random points and sample an exponential function. These points are the sample values for the interpolant.

P = -2.5 + 5*gallery('uniformdata',[200 2],0);x = p(:,1);Y = P(:,2);v = x。* exp(-x。^ 2-y。^ 2);

Create the interpolant, specifying linear interpolation and nearest neighbor extrapolation.

f =散射interpolant.(P,v,'线性','nearest')
f =带有属性的散射interpolant:point:[200x2双]值:[200x1 double]方法:'linear'外推方法:'最近'

评估凸壳外部的内插。

VQ = F(3.0,-1.5)
vq = 0.0031

禁用外推和评估Fat the same point.

F.ExtrapolationMethod ='none';VQ = F(3.0,-1.5)
vq = NaN

More About

全部展开

Tips

  • 评估a更快scatteredInterpolantobjectF在许多不同的查询点集中,它是用函数分别计算插值griddata要么栅格坦.For example:

    % Fast to create interpolant F and evaluate multiple timesf =散射interpolant.(X,Y,V) v1 = F(Xq1,Yq1) v2 = F(Xq2,Yq2)用griddata单独计算插值的百分比慢v1 = griddata(X,Y,V,Xq1,Yq1) v2 = griddata(X,Y,V,Xq2,Yq2)
  • 要更改插值示例值或插值方法,更新内插对象的属性更有效Fthan it is to create a newscatteredInterpolant目的。当你更新时Values要么Method, the underlying Delaunay triangulation of the input data does not change, so you can compute new results quickly.

  • Scattered data interpolation withscatteredInterpolant使用数据的Delaunay三角测量,因此可以对采样点中的缩放问题敏感XG.ydF4y2Ba,yg.ydF4y2Ba,z, 要么P.When this occurs, you can usenormalizeto rescale the data and improve the results. See具有不同量大的数据了解更多信息。

Algorithms

scatteredInterpolantuses a Delaunay triangulation of the scattered sample points to perform interpolation[1]

References

[1] Amidror,Isaac。“电子成像系统的分散数据插值方法:调查”。电子成像杂志.2号卷。11日,2002年4月,pp. 157–176.

在R2013A介绍