populate_matrix function

Populate matrix