Change to pass betamat as a vector to C code instead of as a matrix.