How MATLAB sort works: directions, the [B,I] index output, NaN placement, stability, and sort versus sortrows, checked against MathWorks documentation.