how to do matrix interpolation faster
9 views (last 30 days)
Show older comments
hi: I met a problem when trying to do interpolation with a matrix.
I have base coordinate x,y,z,with size 10000*3, base molar fraction matrix 10000*45 (45 species), and the coordinate I need to interpolate, such as 1000*3. I need to get the interpolation of species 1-45 on the 1000*3 coordinates. so below is my code:
for i=1:1:length(species) spe_itp=scatteredInterpolant(coor_base(:,1),coor_base(:,2),coor_base(:,3),molfra_base(:,i)); molfra_new(:,i)=spe_itp(coor_new); end
however, what I found is that the calculation is too slow. because I have a huge amount interpolation need to do.
so I want know is there anyway to make the interpolation faster? such as interpolation the matrix only once like:
molfra_new(:,i)=interpolate(coor_base,molfra_base,coor_new);
thanks! Li
0 Comments
Answers (1)
Mukul Rao
on 24 Apr 2017
Hi,
One thing I notice is that you are creating the scatteredInterpolant object in each iteration of the for loop. This would definitely cause a slow down if you are performing the interpolation over and over again for each new query point.
I would recommend storing the scatteredInterpolant objects either in a structure or a cell array and then reusing them for every successive query.
Finally, is your data truly scattered? If you do have sufficient scattered points, some of which also happen to lie on a rectangular grid, you could potentially down-sample and perform gridded-interpolation instead and I would be optimistic that it would bring considerable speed up.
1 Comment
John Miers
on 17 Sep 2019
Hey Mukul,
Can you elaborate on what you meant by downsampling and using the gridded-interpolation? I have sample points that are created by a standard meshgrid operation, but that are then offset by unique values at each location. My sample points remain monotonic, but are no longer 'plaid' and I am really looking for something faster than scatteredInterpolant since my output array is at a significant number of well gridded (perfectly meshgridded) query points. Obviously interp3 is generally faster in this case, but since my input sample points are no longer techically 'Plaid' it will not work.
-jcm
See Also
Categories
Find more on Interpolation 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!