MATLAB: Does the SORT function return unsorted values in MATLAB

MATLABones

When I use SORT in the following way,
x = 1:10;
[x2,ind] = sort(x,1,'descend')
x2 is not sorted and ind comes back as a vector of ones.

Best Answer

This is expected behavior in MATLAB and occurs because the vector is being sorted on the wrong dimension. In this case, the vector is a column vector and it each column, containing only one element, is being sorted.
To sort the vector along the proper dimension, either remove the dimension value, like so,
x = 1:10;
[x2,ind] = sort(x,'descend')
or enter a dimension value of 2 to sort vector's rows, like so,
x = 1:10;
[x2,ind] = sort(x,2,'descend')