x <- matrix(1:10, nrow = 2, byrow = TRUE)
z <- shift_array(x, 2, 1, c(1,2))
y <- NA * x
y[1,1:4] = x[1,2:5]
y[2,1:3] = x[2,3:5]
# Check if z ang y are the same
z - y
# array case
# x is Trial x Frequency x Time
x <- array(1:27, c(3,3,3))
# Shift time for each trial, amount is 1, -1, 0
shift_amount <- c(1,-1,0)
z <- shift_array(x, 3, 1, shift_amount)
if(interactive()){
par(mfrow = c(3, 2))
for( ii in 1:3 ){
image(t(x[ii, ,]), ylab = 'Frequency', xlab = 'Time',
main = paste('Trial', ii))
image(t(z[ii, ,]), ylab = 'Frequency', xlab = 'Time',
main = paste('Shifted amount:', shift_amount[ii]))
}
}
Run the code above in your browser using DataLab