View source: R/matchup_funcs.R
get_match | R Documentation |
Given a 2d grid with corresponding x/y coordinates, and another x/y pair of vectors, find the data value closest to the second x/y vector pair. This is similar to pracma::interp2(), but chooses the nearest point instead of interpolating (see below for example).
get_match(grid_x, grid_y, grid_values, x, y)
grid_x |
Numeric vector of x-coordinates for the 2d grid (must match the number of columns in grid_values) |
grid_y |
Numeric vector of y-coordinates for the 2d grid (must match the number of rows in grid_values) |
grid_values |
Numeric matrix with number of columns/rows matchup grid_x and grid_y, respectively |
x |
Numeric vector of x-coordinates where you want to extract the nearest grid_values point (must be same length as y) |
y |
Numeric vector of y-coordinates where you want to extract the nearest grid_values point (must be same length as x) |
Numeric vector of grid values, same length as x and y
# This example is from the help file of pracma::interp2() for 2d interpolation.
x <- linspace(-1, 1, 11)
y <- linspace(-1, 1, 11)
mgrid <- meshgrid(x, y)
Z <- mgrid$X^2 + mgrid$Y^2
xp <- yp <- linspace(-1, 1, 101)
zp <- interp2(x, y, Z, xp, yp, "linear")
# Using get_match:
zp2 <- get_match(x, y, Z, xp, yp)
plot(zp, zp2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.