Why is scatteredInterpolant slower than TriScatteredInterp ?
13 ビュー (過去 30 日間)
古いコメントを表示
I've written a code that uses TriScatteredInterp, but I read in Matlab's documentation that this will not be supported in future release and that I should instead use scatteredInterpolant. So I did, and found to be twice slower for a 512 by 512 matrix. The only difference in my code was just using:
F = scatteredInterpolant(double(x'),double(y'),double(z'),'natural');
instead of
F = TriScatteredInterp(double(x'),double(y'),double(z'),'natural');
Why is that and what can I do to make it faster?
3 件のコメント
Matt J
2013 年 9 月 27 日
編集済み: Matt J
2013 年 9 月 27 日
Even if the construction time does matter to you, I cannot reproduce the slow behavior. I even see slightly faster behavior in scatteredInterpolant for a 512^2 data,
x = rand(512)*4-2;
y = rand(512)*4-2;
z = x.*exp(-x.^2-y.^2);
tic;
obj1 = TriScatteredInterp(x(:),y(:),z(:));
toc
%Elapsed time is 1.475620 seconds.
tic
obj2 = scatteredInterpolant(x(:),y(:),z(:));
toc
%Elapsed time is 1.303282 seconds.
回答 (1 件)
Matt J
2013 年 9 月 26 日
編集済み: Matt J
2013 年 9 月 26 日
You're not supposed to care about the time to construct F. That's only a one-time set-up computation. You're supposed to care about the speed of the actual interpolation operations, which presumably you would be doing repeatedly and on many more points.
In my tests below, I do find scatteredInterpolant to be a bit slower, but certainly not by a factor of 2, and the difference varies with the data sizes. There might be robustness improvements that explain the slower interpolation speed of the new version (better error checking, for example...)
x = rand(100,1)*4-2;
y = rand(100,1)*4-2;
z = x.*exp(-x.^2-y.^2);
obj1 = TriScatteredInterp(x,y,z);
obj2 = scatteredInterpolant(x,y,z);
ti = linspace(-2,2,2e3);
[qx,qy] = meshgrid(ti,ti);
tic;
qz1 = obj1(qx,qy);
toc;
%Elapsed time is 4.324792 seconds.
tic;
qz2 = obj2(qx,qy);
toc
%Elapsed time is 4.990118 seconds.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!