Why is scatteredInterpolant slower than TriScatteredInterp ?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Matt J
le 27 Sep 2013
Modifié(e) : Matt J
le 27 Sep 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.
Réponses (1)
Matt J
le 26 Sep 2013
Modifié(e) : Matt J
le 26 Sep 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.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!