matricized_access-methods: Extract values from a 4D tensor using a matrix of time-space...

matricized_accessR Documentation

Extract values from a 4D tensor using a matrix of time-space indices.

Description

This function efficiently extracts values from a 4D tensor (typically neuroimaging data) using a matrix of indices where each row contains a time index in column 1 and a spatial index in column 2. The spatial index refers to the position in the flattened spatial dimensions (x,y,z). This is primarily used internally by the series() method to efficiently access time series data for specific voxels.

Usage

matricized_access(x, i, ...)

## S4 method for signature 'SparseNeuroVec,matrix'
matricized_access(x, i)

## S4 method for signature 'SparseNeuroVec,integer'
matricized_access(x, i)

## S4 method for signature 'SparseNeuroVec,numeric'
matricized_access(x, i)

## S4 method for signature 'BigNeuroVec,matrix'
matricized_access(x, i)

## S4 method for signature 'BigNeuroVec,integer'
matricized_access(x, i)

## S4 method for signature 'BigNeuroVec,numeric'
matricized_access(x, i)

Arguments

x

a data source, typically a SparseNeuroVec object containing 4D neuroimaging data

i

Either:

  • A matrix with 2 columns: [time_index, space_index] specifying which values to extract

  • A numeric vector of spatial indices to extract all timepoints for those locations

...

additional arguments to be passed to methods.

Value

When i is a matrix, returns a numeric vector of values at the specified time-space coordinates. When i is a vector, returns a matrix where each column contains the full time series for each spatial index.

Examples

# Create a sparse 4D neuroimaging vector
bspace <- NeuroSpace(c(10,10,10,100), c(1,1,1))
mask <- array(rnorm(10*10*10) > .5, c(10,10,10))
mat <- matrix(rnorm(sum(mask)), 100, sum(mask))
svec <- SparseNeuroVec(mat, bspace, mask)

# Extract specific timepoint-voxel pairs
# Get value at timepoint 1, voxel 1 and timepoint 2, voxel 2
idx_mat <- matrix(c(1,1, 2,2), ncol=2, byrow=TRUE)
vals <- matricized_access(svec, idx_mat)

# Get full time series for voxels 1 and 2
ts_mat <- matricized_access(svec, c(1,2))
# Each column in ts_mat contains the full time series for that voxel

bbuchsbaum/neuroim2 documentation built on Feb. 26, 2025, 3:49 p.m.