Write Mat class