https://github.com/cran/pracma
Raw File
Tip revision: 6b5162225f1e90f742ac53c32bf06c8053cff577 authored by HwB on 26 July 2011, 00:00:00 UTC
version 0.7.5
Tip revision: 6b51622
meshgrid.R
##
##  m e s h g r i d . R  Generate a Mesh Grid
##


meshgrid <- function(x, y = x) {
    if (!is.numeric(x) || !is.numeric(y))
        stop("Arguments 'x' and 'y' must be numeric vectors.")

    x <- c(x); y <- c(y)
    n <- length(x)
    m <- length(y)

    X <- matrix(rep(x, each = m),  nrow = m, ncol = n)
    Y <- matrix(rep(y, times = n), nrow = m, ncol = n)

    return(list(X = X, Y = Y))
}
back to top