Alternative to interp2

I am trying to interpolate values in a 2d space. But my code is very slow.
I used the tic toc and found that it is because of interp2 being called multiple times. Is there an alternate for it ? that would be faster ?

Risposte (2)

Ayush Modi
Ayush Modi il 22 Giu 2024
Modificato: Ayush Modi il 10 Lug 2024

1 voto

Hi,
"griddedInterpolant" function will run faster and is recommended by MathWorks as an alternative to calling "interp2" multiple times.
Refer to the following documentation for more information on "griddedInterpolant" function:

1 Commento

Magnate
Magnate il 17 Lug 2024
Thanks Ayush, griddedInterpolant got the run time to the acceptable range.

Accedi per commentare.

John D'Errico
John D'Errico il 22 Giu 2024

1 voto

Perhaps you are calling interp2 multiple times in a loop, when a single call with multiple points will be far faster. This would be true also with griddedInterpolant. Both tools will be internally optimized to perform much better in a vectorized way.

1 Commento

Magnate
Magnate il 17 Lug 2024
It is not inside a loop. but I will read about vectorized way. thanks.

Accedi per commentare.

Categorie

Richiesto:

il 22 Giu 2024

Commentato:

il 17 Lug 2024

Community Treasure Hunt

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

Start Hunting!

Translated by