필터 지우기
필터 지우기

Interpolation using scattered query points

조회 수: 2 (최근 30일)
Hesham
Hesham 2019년 8월 9일
댓글: Hesham 2019년 8월 9일
Hi
It is straight forward to use interpn or griddedInterpolant to perform n-dim interpolation. However, in these functions, the query points must be on a full grid. Is it possible to perform interpolation on a scattered set of query points?
As an example, for 2D interpolation, I don't want to perform interpolation on a full xy grid. I just want to perform interpolation on a set of points {(x1,y1), (x2,y2), (x3,y3), ...}. I know it can be done using a loop, but I was looking for a faster and more efficient vectorized solution.
The question at the link below is similar to my question, but the answer didn't give a vectorized solution.
Thanks

채택된 답변

the cyclist
the cyclist 2019년 8월 9일
I believe the solution you point to can be trivially vectorized:
load clown ;
imagesc(X);
colormap gray ;
[nx,ny] = size(X) ;
r = 1:ny ;
c = 1:nx ;
[R,C] = meshgrid(r,c) ;
%%do interpolation
Ri = [5 6]; Ci = [5 7]; % <------- I VECTORIZED THE CODE RIGHT HERE.
Xi1 = interp2(R,C,X,Ri,Ci) ;
% or can be used without mesh grid like below
Xi2 = interp2(r,c,X,Ri,Ci) ;
  댓글 수: 4
the cyclist
the cyclist 2019년 8월 9일
편집: the cyclist 2019년 8월 9일
Hm. For me, the output of the code I posted yields two points.
Xi1 = [61 55];
I wonder if it is a version issue? I am using R2019a.
Hesham
Hesham 2019년 8월 9일
It turned out that the answer is quite simple! The code below works as I need.
@the cyclist: Many thanks for pointing out the solution is trivial!
[x,y] = ndgrid(0:1:10);
z = x.^2 + y.^2;
F = griddedInterpolant(x,y,z);
vq = F([1 3; 2 4])

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by