1 | ind2sub(siz, ndx)
|
siz |
|
ndx |
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
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.