# Help understanding interp2?

86 visualizaciones (últimos 30 días)
Troy McClure el 15 de Jun. de 2020
Comentada: Troy McClure el 16 de Jun. de 2020
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?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

John D'Errico el 15 de Jun. de 2020
Editada: John D'Errico el 15 de Jun. de 2020
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 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
John D'Errico el 16 de Jun. de 2020
Editada: John D'Errico el 16 de Jun. de 2020
[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 el 16 de Jun. de 2020
Thanks, this is a really good breakdown.

Iniciar sesión para comentar.

### Más respuestas (1)

madhan ravi el 15 de Jun. de 2020
V(X,Y) -> function Xq & Yq are query points
query points -> what would be the functions value at these points.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Troy McClure el 15 de Jun. de 2020
Not sure I understand still. Which 2 variables are being interpolated between and what value is being used to do the interpolation?

Iniciar sesión para comentar.

### Categorías

Más información sobre Interpolation en Help Center y File Exchange.

### Etiquetas

Aún no se han introducido etiquetas.

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by