3D Spline Interpolation Matlab

徘徊边缘 提交于 2019-12-01 13:35:33

I don't quite understand your data, is B a function of A (or visa versa)? Also, those arrays appear to be 1D, not 3D. Can you clarify this?

In your function call

yy = spline(x, Y, xx)

Y is the dependent variable which you are interpolating: Y is a function of x and the result of the above function call is to return the value of Y at xx. As an example in one dimension, try

x = linspace(0., 2.*pi, 100);
Y = sin(x);

% What is the value of Y (or sin(x)) at pi/2?
xx = pi/2.;
yy = spline(x, Y, xx); % This should result in yy = 1.000

Check out the spline documentation for more information and examples of using this function.

Now this function is only for 1D fitting, and is (I presume) equivalent to yy = interp1(x, Y, xx, 'spline'). If you want to do a three dimensional lookup, you'll have to use interp3, which generalises the above example to 3D. So rather than just one independent coordinate x, we have two more, y, and z and three coordinates for the point at which we want to perform the look up: xx, yy and zz. The function you are interpolating must be a 3D function of the coordinates (x, y, z). Try, as an example:

x = linspace(-1., 1., 100); y = x; z = x;
[X, Y, Z] = meshgrid(x, y, z);
s = exp(-sqrt(X.^2 + Y.^2 + Z.^2));

sinterp = interp3(x, y, z, s, 0., 0., 0.) % Should give sinterp = 0.9827
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!