worked out catchmatrix.R