The bug is in your interpretation of the indices returned by sort. As per the documentation of sort in R2015a:
[B,I] = sort(...) additionally returns a collection of index vectors for any of the previous syntaxes. I is the same size as A and describes the arrangement of the elements of A into B along the sorted dimension. For example, if A is a numeric vector, B = A(I).
It behaves exactly as documented. This may not be what you want but it is what it does. It's not particularly difficult to transform the column indices into linear indices:
iSort = sub2ind(size(A), repmat((1:size(A, 1))', 1, size(A, 2)), iSort);