Check dimensions of matrices.