Change grid cell size and interpolate values from old grid into new grid.

17 visualizaciones (últimos 30 días)
Luke
Luke el 11 de Sept. de 2024
Respondida: Shashi Kiran el 12 de Sept. de 2024
I currently have a bathymetric grid that is 1504 m x 1217 m, with a matrix size of 356x583. This means the grid cell size is roughly 2.58 x 3.42 and is therefore slightly rectangular.
I would like to create a grid that is a square 3 x 3 resolution to cover this domain, which will be a 405 x 501 matrix (1215m x 1503m), and interpolate the values of the old matrix into the new one. I have heard that I can use interp2, or griddata to do this, but I'm not 100% sure where to start. Could someone give me a couplke of pointers to get me on the way to achieving this?
Thanks!

Respuestas (1)

Shashi Kiran
Shashi Kiran el 12 de Sept. de 2024
Hi Luke,
I understand that you want to interpolate your bathymetric grid from a 356x583 matrix to a grid with square cells of 3x3 resolution.
The interp2 function is used for grid-based interpolation and griddata for scattered data interpolation. Since your data is structured as a matrix, interp2 function will help you achieve the desired reults..
Here are some suggestions to help you get started on achieving this.
  • The original grid is 356x583, representing an area of 1504m x 1217m.
  • The target grid will be 406x502, as it spans from 0 to 1503 and 0 to 1215 with square cells of 3x3 meters, covering a total area of 1503m x 1215m.
Z = rand(356, 583); % Random data
x_old = linspace(0, 1504, 583);
y_old = linspace(0, 1217, 356);
[x_old_grid, y_old_grid] = meshgrid(x_old, y_old); % Original grid
% Define the target grid with square cells of size 3x3 (1503m x 1215m)
x_new = linspace(0, 1503, 502); % New X coordinates (1503m, 501 points)
y_new = linspace(0, 1215, 406); % New Y coordinates (1215m, 405 points)
[x_new_grid, y_new_grid] = meshgrid(x_new, y_new); % Target grid
  • Create the grids and use interp2 to interpolate
Z_new = interp2(x_old_grid, y_old_grid, Z, x_new_grid, y_new_grid, 'linear');
Refer to the following documentations for more details about the functions:
Hope this helps.

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!

Translated by