Learn R Programming

fMRItools (version 0.7.2)

unvec_mat: Transform vector data to image

Description

From a \(v \times p\) matrix of vectorized data and an \(m \times n\) image mask with \(v\) in-mask locations, create a list of \(p\) \(m \times n\) data arrays in which the mask locations are filled in with the vectorized data values.

Consider using abind::abind to merge the result into a single array.

Usage

unvec_mat(x, mask, fill_value = NA)

Value

A list of masked values from x

Arguments

x

\(v \times p\) matrix, where \(v\) is the number of voxels within a mask and \(p\) is the number of vectors to transform into matrix images.

mask

\(m \times n\) logical matrix in which v entries are TRUE and the rest are FALSE.

fill_value

Out-of-mask value in the output image. Default: NA.

Examples

Run this code
x <- unvec_mat(
 cbind(seq(3), seq(2,4), seq(3,5)), 
 matrix(c(rep(TRUE, 3), FALSE), ncol=2),
 0
)
y <- array(c(1,2,3,0,2,3,4,0,3,4,5,0), dim=c(2,2,3))
stopifnot(identical(x[[1]], y[,,1]))
stopifnot(identical(x[[2]], y[,,2]))
stopifnot(identical(x[[3]], y[,,3]))

Run the code above in your browser using DataLab