Better method to interpn when one grid is fixed?

4 views (last 30 days)
I currently have a n-D sized database, and I'm using interpn to interpolate values from it. However, I do not interpolate on the last dimension, as I'm using the database to interpolate between 1xn solutions. The database is very large, and I am interpolating on it many times, so I'm looking for a faster solution. I believe there should be a faster solution since I'm not necessarily "interpolating" between values on the last dimension. Below is an example of my current method that I am looking to improve:
Example:
database=rand([4,4,2,3,8,6,2,6,5500]);
interpGrids={[1000 2000 4000 7000],[-5 -2 2 5],[0 1],[-5 0 5],[-20 -15 -5 0 5 10 15 20],[10 20 30 40 50 60],[-5 0],[.1 .2 .3 .4 .5 1],1:5500};
ngGriddedData=cell(1,9);
[ngGriddedData{:}]=ndgrid(interpGrids{:});
tic
solution=interpn(ngGriddedData{:},database,3000,1,1,2,-17,35,-4,.35,1:5500);
toc
Many many thanks for any suggestions. I'll be sure to send some good computing karma your way.
- Sean

Accepted Answer

Prashant Arora
Prashant Arora on 6 Mar 2017
Hi Sean,
You can use the griddedInterpolant function, which provides performance improvements for repeated queries to the interpolant.
F = griddedInterpolant(interpGrids,database);
tic
solution2 = F({3000,1,1,2,-17,35,-4,.35,1:5500});
toc
  1 Comment
Sean
Sean on 7 Mar 2017
Oh my goodness... I completely forgot about griddedInterpolant. Thank you!

Sign in to comment.

More Answers (0)

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!