Add a BuildMatrix function.