interp2(x, y, Z, xp, yp, method = c("linear", "nearest", "constant"))
Z
.length(x)
-by-length(y)
matrix.xp
of interpolated values.For methods ``constant'' and ``nearest'' the intervals are considered closed from left and below. Out of range values are returned as NAs.
xp
and yp
, determining by interpolation within the
two-dimensional function specified by vectors x
and y
,
and matrix Z
.
x
and y
must be monotonically increasing. They specify
the points at which the data Z
is given.
Therefore, length(x) = nrow(Z)
and length(y) = ncol(Z)
must be satisfied. xp
and yp
must be of the same length.
The functions appears vectorized as xp
, yp
can be
vectors, but internally they are treated in a for
loop.
interp1
, barylag2d
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)
method <- "linear"
zp <- interp2(x, y, Z, xp, yp, method)
plot(xp, zp, type = "l", col = "blue")
method = "nearest"
zp <- interp2(x, y, Z, xp, yp, method)
lines(xp, zp, col = "red")
grid()
Run the code above in your browser using DataLab