ind2sub:

Usage Arguments Examples

Usage

1
ind2sub(siz, ndx)

Arguments

siz
ndx

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (siz, ndx) 
{
    nout = 2
    siz = as.double(siz)
    len = end(siz)[1]
    if (length(siz) <= nout) {
        siz = c(siz, numeric(nout - length(siz)))
    }
    else {
        siz = c(siz[1:(nout - 1)], prod(siz[nout:len]))
    }
    n = length(siz)
    k = c(1, cumprod(siz[1:(len - 1)]))
    varargout = numeric(n)
    for (i in rev(1:n)) {
        vi = rem(ndx - 1, k[i]) + 1
        vj = (ndx - vi)/k[i] + 1
        varargout[i] = vj
        ndx = vi
    }
    varargout
  }

galuardi/hmmwoa documentation built on May 16, 2019, 5:37 p.m.