Max*_*xPY 6 matlab interpolation
如何创建2个变量的函数并给定2D数组,它将返回一个插值?
我有N x M阵列A.我需要插入它并以某种方式获得该表面的功能,以便我可以选择非整数参数的值.(我需要使用插值作为2个变量的函数)
例如:
A[N,M] //my array
// here is the method I'm looking for. Returns function interpolatedA
interpolatedA(3.14,344.1) //That function returns interpolated value
Run Code Online (Sandbox Code Playgroud)
这是一个使用示例scatteredInterpolant:
%# get some 2D matrix, and plot as surface
A = peaks(15);
subplot(121), surf(A)
%# create interpolant
[X,Y] = meshgrid(1:size(A,2), 1:size(A,1));
F = scatteredInterpolant(X(:), Y(:), A(:), 'linear');
%# interpolate over a finer grid
[U,V] = meshgrid(linspace(1,size(A,2),50), linspace(1,size(A,1),50));
subplot(122), surf(U,V, F(U,V))
Run Code Online (Sandbox Code Playgroud)

请注意,您可以在任何时候评估插值对象:
>> F(3.14,3.41)
ans =
0.036288
Run Code Online (Sandbox Code Playgroud)
上面的例子使用向量化调用在网格的所有点进行插值
对于规则网格上的数据,请使用interp2。如果您的数据分散,请使用griddata。您可以创建一个匿名函数作为这些调用的简化包装器。
M = 10;
N = 5;
A = rand(M,N);
interpolatedA = @(y,x) interp2(1:N,1:M,A,x,y);
%interpolatedA = @(y,x) griddata(1:N,1:M,A,x,y); % alternative
interpolatedA(3.3,8.2)
ans =
0.53955
Run Code Online (Sandbox Code Playgroud)