Convert 1d indices to n-dimensional grid coordinates
Source:R/all_generic.R
, R/neuroslice.R
, R/neurospace.R
index_to_grid-methods.Rd
Converts linear indices to 2D grid coordinates for a NeuroSlice
object.
Usage
index_to_grid(x, idx)
# S4 method for class 'NeuroSlice,numeric'
index_to_grid(x, idx)
# S4 method for class 'NeuroSpace,numeric'
index_to_grid(x, idx)
# S4 method for class 'NeuroVec,index'
index_to_grid(x, idx)
# S4 method for class 'NeuroVec,integer'
index_to_grid(x, idx)
# S4 method for class 'NeuroVol,index'
index_to_grid(x, idx)
# S4 method for class 'NeuroVol,integer'
index_to_grid(x, idx)
Value
a matrix of grid coordinates
A matrix with 2 columns representing the (x,y) coordinates corresponding to the input indices
See also
grid_to_index
for the inverse operation
Examples
bvol <- NeuroVol(array(0, c(10,10,10)), NeuroSpace(c(10,10,10), c(1,1,1)))
idx <- 1:10
g <- index_to_grid(bvol, idx)
bvol[g]
#> [1] 0 0 0 0 0 0 0 0 0 0
slice_space <- NeuroSpace(c(10, 10))
slice_data <- matrix(1:100, 10, 10)
slice <- NeuroSlice(slice_data, slice_space)
# Convert single index
coords <- index_to_grid(slice, 55)
# Convert multiple indices
indices <- c(1, 25, 50, 75, 100)
coords_mat <- index_to_grid(slice, indices)