Structure of algebras of commutative matrices