interp2 MATLAB有更好的方法吗?

问题描述:

使用MATLAB我有一个表,让我们说,X(大小(100X1)),Y(大小(100X1))和z(尺寸(100×100)),我使用:interp2 MATLAB有更好的方法吗?

z1 = interp2(x,y,z,x1,x2) 

找到价值,我需要以后计算。有没有更高效/更快的方法来实现这一点?我尝试使用scatterInterpolant来实现它并不成功。

我不确定你的问题。你是指一个更好的电话,而不是interp2,或关于元组(x1, x2)

如果您指的是interp2,您可以通过在matlab >>> type interp2中输入最终matlab调用griddedInterpolant来看到。我无法在线找到此内置呼叫的代码,但this链接表示interp2很快。 interpn对于GPU而言是过载的,或许interp2现在或可能在将来。

在我看来,interp2函数本身非常方便。我广泛使用interp。有多种不同类型的多项式插值和一些外插度量。

没有一个更好的问题的定义,我不得不离开它。希望这可以帮助。

+0

嘿there.I试着用interp2,griddenInterpolant和scatteredInterpolant。我发布了计算时间的摘要:interp2:5.18sec,griddenInterpolant:4.8sec,scatteredInterpolant:10,1sec – 2014-10-19 10:35:32

+0

'interp2'在调用'griddedInterpolant'之前执行了很多检查,这是其性能降低了〜400ms的原因。 'interp2'是'griddedInterpolant'的封装。 – JayInNyc 2014-10-19 12:38:57

这将取决于您的数据和要插入的点。如果数据在对齐的网格中,则可以使用griddata。 如果数据分散,点到插在一个网格,scatteredInterpolant应该确定:

%% // scattered data, interpolate at grid 
% // random coordinate pair 
x = rand(100,1); 
y = rand(100,1); 
% // function to interpolate 
func = sin(x.*y); 
% // interp function 
F = scatteredInterpolant(x,y,func); 
% // grid to interpolate at: 
[ix iy] = ndgrid(0:.01:1); 
ifunc = F(ix, iy); 
% // plot 
mesh(ix, iy, ifunc); 

%% // grid data, scattered interpolation 
[x y] = ndgrid(1:100); % // data coordinates 
func = sin(x.*y);  % // create some data 
ix = rand(100,1)*100; % // interpolation points 
iy = rand(100,1)*100; 
ifunc = griddata(x,y,func,ix,iy); % // interpolate 
plot3(ix, iy, ifunc, 'o'); % // plot 

如果需要散射散插... 我之前曾与MATLAB同样的问题,我最终做了一个更复杂的解决方案,因为matlab函数根本没有效率。