Better method to interpn when one grid is fixed?

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

 采纳的回答

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 个评论

Oh my goodness... I completely forgot about griddedInterpolant. Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by