add ToSlice function for matrix