Code for Matrix