How to calculete matrix fields