2014-10-18 52 views
0

使用MATLAB我有一個表,讓我們說,X(大小(100X1)),Y(大小(100X1))和z(尺寸(100×100)),我使用:interp2 MATLAB有更好的方法嗎?

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

找到價值,我需要以後計算。有沒有更高效/更快的方法來實現這一點?我嘗試使用scatterInterpolant來實現它並不成功。

回答

0

我不確定你的問題。你是指一個更好的電話,而不是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

0

這將取決於您的數據和要插入的點。如果數據在對齊的網格中,則可以使用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函數根本沒有效率。