R/linspace.R

## Function written to match MATLAB function
## Author: Andrew Hooker

linspace <- function (a, b, n = 100) 
{
    if (!is.numeric(a)) {
        stop(sprintf("argument %s must be numeric", sQuote("a")))
    }
    else if (!(length(a) == 1)) {
        stop(sprintf("argument %s must be of length 1", sQuote("a")))
    }
    if (!is.numeric(b)) {
        stop(sprintf("argument %s must be numeric", sQuote("b")))
    }
    else if (!(length(b) == 1)) {
        stop(sprintf("argument %s must be of length 1", sQuote("b")))
    }
    if (!is.numeric(n)) {
        stop(sprintf("argument %s must be numeric", sQuote("n")))
    }
    else if (!(length(n) == 1)) {
        stop(sprintf("argument %s must be of length 1", sQuote("n")))
    }
    n <- floor(n)
    if (n < 2) {
        b
    }
    else {
        seq(a, b, length = n)
    }
}
andrewhooker/PopED documentation built on Nov. 23, 2023, 1:37 a.m.