2D Interpolation/Extrapolation on Irregular shaped grid
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm starting with a grid that is evenly distributed over a recangular region:
M = load("function_matrix.mat")
function_matrix = M.function_matrix
[x,y] = meshgrid((1:20),(1:20))
I have 20x20 matrix that contains the values of a function over a subregion of this grid, and everywhere outside of this subregion the matrix has the value 0 (I've attached it to this post). The subregion where I do have the values is given by the below indexing matrix (1 corresponds to having the value and 0 corresponds to not having the value and just having a placeholder 0 in the function_matrix. My hope was to use interp2 to extrapolate to the values I don't have. I was going to do that with the following code:
id_matrix = logical([ 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1]);
extrapolated_function_matrix = interp2(x(id_matrix),y(id_matrix),function_matrix(id_matrix),x,y,'spline')
However, this gives me the following error: "The grid vectors must contain unique points."
I did some search on the forum, and people suggested using the unique() function on the coordinates, but that gave me another error. I just wanted to know if there was a way to extrapolate from a subregion of a grid to the whole grid like I am trying to do.
Thanks!
1 comentario
Respuestas (1)
Torsten
el 13 de Dic. de 2023
Editada: Torsten
el 13 de Dic. de 2023
In order to use "interp2", you must specify a rectangular region where values of your function are given on a regular grid. Thus if you use 1:20 x 1:20 as rectangular region, you must specify values for f at 1:20 x 1:20. But if you had values on 1:20 x 1:20, there wouldn't be the need to extrapolate. So "interp2" is not useful to solve your problem.
You will have to use "scatteredInterpolant". But don't be disappointed if the extrapolated values are far from what you expect.
0 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!