问题
I have two 3D arrays:
A=[
12751 4616 15915
15864 4622 15667
12877 4683 21050
15816 4668 21253
11374 5006 18495
16995 5466 18493
11638 4880 20023
17078 4938 20006
11576 4886 17011
];
and
B=[
12402 2138 15743
10285 3175 15851
10237 3084 21052
12130 2129 21299
8074 3802 18505
14515 1623 18497
8415 3713 19856
14462 1120 20061
8340 3711 17145
14483 1157 16990];
and I want to do spline or 3D interpolation between them using Interp3 in Matlab.How should I define V in VI = interp3(X,Y,Z,V,XI,YI,ZI)?
Or Y in yy = spline(x,Y,xx).
回答1:
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
来源:https://stackoverflow.com/questions/10352662/3d-spline-interpolation-matlab