Better method to interpn when one grid is fixed?

6 vues (au cours des 30 derniers jours)
Sean
Sean le 3 Mar 2017
Commenté : Sean le 7 Mar 2017
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

Réponse acceptée

Prashant Arora
Prashant Arora le 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 commentaire
Sean
Sean le 7 Mar 2017
Oh my goodness... I completely forgot about griddedInterpolant. Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by