Add to_binary and from_binary methods to matrices.

to_binary serialises a matrix to a string in the same format as fwrite.

from_binary reads from a string in the same format into a matrix, which
most be of the correct size.

This is currently only implemented for integer and double matrices,
though it should be easy enough to port to other types.