How to accelerate the speed of frequent interpolation?
Show older comments
For example,
I have a point set( A), where each point corresponds to a value of (Value_A). We can use "scatteredInterpolant" function to obtain the value (Value_B) on a point set B. The number of points in the point set B may be more or less than that in the point set A. However, this process is very time-consuming for a large number of points.
In my code, this interpolation process is required frequent operations, but the point sets A and B do not change, only the value (value_A) on the points will change.
In this case, can we extract the weight matrix A2B from A to B and directly obtain (Value_B) through Value_A * A2B. This way, the overall efficiency will be very high. I tried to check the underlying code of the scatteredInterpolant function, but it was not available.
Accepted Answer
More Answers (1)
How are you repeating your interpolation? Are you recreating the scatteredInterpolant object each time? If so, instead follow the "Replacement of Sample Values" example on that documentation page to use the same triangulation each time.
rng('default')
x = -2.5 + 5*rand([50 1]);
y = -2.5 + 5*rand([50 1]);
v = x.*exp(-x.^2-y.^2);
tic
F = scatteredInterpolant(x,y,v);
toc
xsample = -2.5:0.1:2.5;
ysample = -2.5:0.1:2.5;
tic
v1 = F(xsample, ysample);
toc
vnew = x.^2 + y.^2;
tic
F.Values = vnew;
v2 = F(xsample, ysample);
toc
Changing the values and interpolating does take longer than simply interpolating the original values, but it takes less time than creating the scatteredInterpolant object initially then interpolating. Granted in this case it's close because there are only 50 points, but try it with your own (I'm guessing larger) data set.
tic
F = scatteredInterpolant(x, y, vnew);
v3 = F(xsample, ysample);
toc
1 Comment
Categories
Find more on Delaunay Triangulation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!