Why is scatteredInterpolant slower than TriScatteredInterp ?

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 comentarios

Matt J
Matt J el 26 de Sept. de 2013
Editada: Matt J el 26 de Sept. de 2013
Your calls to double() and ctranspose() could have affected the speed comparison.
I doubt it. I use the exact same input for TriScatteredInterp.
Matt J
Matt J el 27 de Sept. de 2013
Editada: Matt J el 27 de Sept. de 2013
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.

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 26 de Sept. de 2013
Editada: Matt J el 26 de Sept. de 2013
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.

Categorías

Productos

Preguntada:

el 25 de Sept. de 2013

Comentada:

el 27 de Sept. de 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by