adjust_matrix function

Adjust to matrix