add write function for matcrs