I am using the sort function to sort values in each row of a large matrix. The function returns the correct sorted matrix, but not always the correct indices.
The row highlighted in the screenshot below provides an example (columns 1-3 are the original matrix, columns 4-6 are the sorted matrix, and columns 7-9 are the indices). In row 870, the sorted values are in the correct order, but the indices are in the opposite order. Notice the function gives the correct answer for all other lines in this example.
What am I doing wrong?