I'm performing 2-D interpolation on a large gridded dataset. The method of call I'm using is
vals = interp2(V,Xq,Yq)
Where V is a large image, but Xq and Yq are fairly sparse in comparison to the image size. Xq and Yq may be invalid, so I do need to preserve the NaN returns when they are.
The code is painfully slow and running the profiler shows that line 105 in interp2 is the culprit
V = V.';
is taking 82% of the execution time! (Not sure why the author chose to transpose V rather than just swap the index arrays, but whatever, that's a Matlab "bug" I guess.)
Is there an alternate way to do this without interp2 so that I can avoid the unnecessary and wasteful transpose? Should I just call makegriddedinterp() directly the way it looks like interp2 does anyway (and swap X and Y in the call)?

댓글 수: 3

Philip Freeman
Philip Freeman 2022년 1월 20일
Digging in, I see that interp2's call to makegriddedinterpolant calls the Matlab builtin griddedInterpolant(). I'll try calling that directly rather than interp2.
Sean de Wolski
Sean de Wolski 2022년 1월 20일
In general using griddedInterpolant will also be faster for subsequent interpolations because you build it once, it does the underlying computations once, and then are reused. This only helps if you need to call multiple times though.
Philip Freeman
Philip Freeman 2022년 1월 20일
Thanks, Sean. That is what I ended up doing and the performance is greatly improved.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2022년 1월 20일

댓글:

2022년 1월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by