function to convert matrices to bigarrays