code in matrix way