I have a square matrix and I want to get a 2 by n matrix that will have indices of matrix in a sorted order. For example, I want to get from this matrix

0 0 0

1 0 0

2 3 0

something like this

[3 2; 3 1; 2 1] ....

(3,2) being the indices of the biggest element in the matrix, (3,1) the second biggest and so on. It would be good if it could ignore zeros (or NaN-s instead of zeros).

Additional information about the matrix: it is positive, but not necessarily 3 by 3, diagonal elements and every element above the diagonal is either 0 or NaN (a side question, which is processed faster, NaNs or 0s?)