Can someone explain to me how interp2(X,Y,V,Xq,Yq) works? I've read the matlab docs, but they aren't very clear. Can anyone explain how it works more plainly?

 채택된 답변

John D'Errico
John D'Errico 2020년 6월 15일
편집: John D'Errico 2020년 6월 15일

2 개 추천

Interp2 is a tool that allows you to interpolate on a gridded domain. So a grid based on meshgrid, in the (x,y) plane. The presumption is you have some array V, that defines V(x,y).
Xq and Yq are now a list of points to interpolate over that grid.
Interp2 is NOT there to interpolate over scattered data points, thus a point cloud in the (x,y) plane. That purpose is served by tools like griddata and scatteredInterpolant.

댓글 수: 3

Troy McClure
Troy McClure 2020년 6월 16일
So what I'm trying to do is implement interp2 in C, which I can't do until I know what interp2 does, but I'm still having trouble understanding what you mean by a couple points here.
So if V, X, and Y are all 2D arrays, are you saying the value at V[1][1] contains the output of the function V(X[1][1], Y[1][1])? If so, I don't understand why X and Y are even needed by interp2.
Secondly, are you saying Xq contains the X components of a list of points and Yq contains the Y components of that same list of points? So the 1st query point would be Xq[1],Yq[1]?
I'm also not sure what is meant by "interpolate over a grid". V(X,Y) does not appear to define a grid but a 1D array since for each set of 2 inputs (a point) it gives a single output. What grid is being interpolated over?
John D'Errico
John D'Errico 2020년 6월 16일
편집: John D'Errico 2020년 6월 16일
[x,y] = meshgrid(0:2,0:3)
x =
0 1 2
0 1 2
0 1 2
0 1 2
y =
0 0 0
1 1 1
2 2 2
3 3 3
z = x.^2 + y.^2
z =
0 1 4
1 2 5
4 5 8
9 10 13
Given only the gridded lattice in the (x,y) plane, you have created z(x,y). Do you accept that?
Interp2 alllows you to compute z(1.5,2.3), given only the information in the arrays x, y, and z. This is called interpolation. Of course it will not be exact, but a relatively coarse approximation, since the true underlying function is not known. (At least it is not known to interp2.)
interp2(x,y,z,1.5,2.3)
ans =
8
1.5^2 + 2.3^2
ans =
7.54
As I said, not a perfect approximation, but the default for interp2 is a tensor product linear interpolant. A spline interpolant will do better.
interp2(x,y,z,1.5,2.3,'spline')
ans =
7.54
Since the function was truly quadratic, logically a cubic spline interpolant would do pretty well.
If none of this still makes any sense, then you need to do some serious reading about interpolation in multiple dimensions.
Troy McClure
Troy McClure 2020년 6월 16일
Thanks, this is a really good breakdown.

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

추가 답변 (1개)

madhan ravi
madhan ravi 2020년 6월 15일
편집: madhan ravi 2020년 6월 15일

0 개 추천

V(X,Y) -> function Xq & Yq are query points
query points -> what would be the functions value at these points.

댓글 수: 1

Troy McClure
Troy McClure 2020년 6월 15일
Not sure I understand still. Which 2 variables are being interpolated between and what value is being used to do the interpolation?

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

카테고리

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

제품

릴리스

R2019b

태그

아직 태그를 입력하지 않았습니다.

질문:

2020년 6월 15일

댓글:

2020년 6월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by