replace matrix with hmatrix