Why is scatteredInterpolant slower than TriScatteredInterp ?
6 次查看(过去 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!