griddata
Interpolates scattered data – generally to produce gridded data
Vq = griddata(X,Y,V,Xq,Yq) fits a surface of the form V = F(X,Y) to the
scattered data in (X, Y, V). The coordinates of the data points are
defined by the vectors (X,Y) and V defines the corresponding values.
griddata interpolates the surface F at the query points (Xq,Yq) and
returns the values in Vq. The query points (Xq, Yq) generally represent
a grid obtained from NDGRID or MESHGRID, hence the name griddata.
Vq = griddata(X,Y,Z,V,Xq,Yq,Zq) fits a hyper-surface of the form
V = F(X,Y,Z) to the scattered data in (X, Y, Z, V). The coordinates of
the data points are defined by the vectors (X,Y,Z) and V defines the
corresponding values. griddata interpolates the surface F at the query
points (Xq,Yq,Zq) and returns the values in Vq.
Vq = griddata(X,Y,V, xq, yq) where xq is a row vector and yq is a
column vector, expands (xq, yq) via [Xq, Yq] = meshgrid(xq,yq).
[Xq, Yq, Vq] = griddata(X,Y,V, xq, yq) returns the grid coordinates
arrays in addition.
Note: The syntax for implicit meshgrid expansion of (xq, yq) will be
removed in a future release.
griddata(…, METHOD) where METHOD is one of
‘nearest’ – Nearest neighbor interpolation
‘linear’ – Linear interpolation (default)
‘natural’ – Natural neighbor interpolation
‘cubic’ – Cubic interpolation (2D only)
‘v4’ – MATLAB 4 griddata method (2D only)
defines the interpolation method. The ‘nearest’ and ‘linear’ methods
have discontinuities in the zero-th and first derivatives respectively,
while the ‘cubic’ and ‘v4’ methods produce smooth surfaces. All the
methods except ‘v4’ are based on a Delaunay triangulation of the data.
Example 1:
% Interpolate a 2D scattered data set over a uniform grid
x = 4*rand(100,1)-2; y = 8*rand(100,1)-4; z = x.*exp(-x.^2-y.^2);
[xq,yq] = meshgrid(-2:.2:2, -4:.4:4);
zq = griddata(x,y,z,xq,yq);
mesh(xq,yq,zq), hold on, plot3(x,y,z,’o’), hold off
Example 2:
% Interpolate a 3D data set over a grid in the x-y (z=0) plane
x = 2*rand(5000,1)-1;
y = 2*rand(5000,1)-1;
z = 2*rand(5000,1)-1;
v = x.^2 + y.^2 + z.^2;
d = -0.8:0.05:0.8;
[xq,yq,zq] = meshgrid(d,d,0);
vq = griddata(x,y,z,v,xq,yq,zq);
surf(xq,yq,vq);
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/35823.html