MATLAB: Sort( ) do not work (or?)

functionMATLAB

Hello, Got a strange problem with the sort( ) function (I tried with sortrows as well, – same problem exist)..
I just attached the result of two different data tests. In both tests, I show the not sorted data, and the sorted data.. Each number is taken from a 1×1 cell.
Why can it be, that it does not sort the second test?
Hope to hear from someone, thanks in advance.
-best

Best Answer

Both are sorted, but as the quotes around the data show the data are stored as cell strings so it's in ASCII order, not numeric. Convert the cellstring array to numeric prior to sorting...
sort(str2num(char(x)))
or equivalent where x is the cell array.
The first looks ok because all are of the same order of magnitude between 0-1 while the latter change. If you note, they're sorted by the first character of the number in order first.