Here is some data I'm trying to sort by rows:
-80.0000 5.6250 1.0000-45.0000 5.6250 1.0000 45.0000 5.6250 1.0000-65.0000 5.6250 1.0000 25.0000 5.6250 1.0000-40.0000 5.6250 1.0000-25.0000 5.6250 1.0000-15.0000 5.6250 1.0000-10.0000 5.6250 1.0000 0 5.6250 1.0000 10.0000 5.6250 1.0000 15.0000 5.6250 1.0000 35.0000 5.6250 1.0000-35.0000 5.6250 1.0000-30.0000 5.6250 1.0000-20.0000 5.6250 1.0000 -5.0000 5.6250 1.0000 5.0000 5.6250 1.0000 20.0000 5.6250 1.0000 40.0000 5.6250 1.0000-55.0000 5.6250 1.0000 30.0000 5.6250 1.0000 55.0000 5.6250 1.0000 65.0000 5.6250 1.0000 80.0000 5.6250 1.0000
If I do
sortrows(data,1);
I get the following desired result:
-80.0000 5.6250 1.0000-65.0000 5.6250 1.0000-55.0000 5.6250 1.0000-45.0000 5.6250 1.0000-40.0000 5.6250 1.0000-35.0000 5.6250 1.0000-30.0000 5.6250 1.0000-25.0000 5.6250 1.0000-20.0000 5.6250 1.0000-15.0000 5.6250 1.0000-10.0000 5.6250 1.0000 -5.0000 5.6250 1.0000 0 5.6250 1.0000 5.0000 5.6250 1.0000 10.0000 5.6250 1.0000 15.0000 5.6250 1.0000 20.0000 5.6250 1.0000 25.0000 5.6250 1.0000 30.0000 5.6250 1.0000 35.0000 5.6250 1.0000 40.0000 5.6250 1.0000 45.0000 5.6250 1.0000 55.0000 5.6250 1.0000 65.0000 5.6250 1.0000 80.0000 5.6250 1.0000
However, if I do
sortrows(data,[2,1]);
I get the following wrong result:
-80.0000 5.6250 1.0000-45.0000 5.6250 1.0000 45.0000 5.6250 1.0000-65.0000 5.6250 1.0000 25.0000 5.6250 1.0000-40.0000 5.6250 1.0000-25.0000 5.6250 1.0000-15.0000 5.6250 1.0000-10.0000 5.6250 1.0000 0 5.6250 1.0000 10.0000 5.6250 1.0000 15.0000 5.6250 1.0000 35.0000 5.6250 1.0000-35.0000 5.6250 1.0000-30.0000 5.6250 1.0000-20.0000 5.6250 1.0000 -5.0000 5.6250 1.0000 5.0000 5.6250 1.0000 20.0000 5.6250 1.0000 40.0000 5.6250 1.0000-55.0000 5.6250 1.0000 30.0000 5.6250 1.0000 55.0000 5.6250 1.0000 65.0000 5.6250 1.0000 80.0000 5.6250 1.0000
Can someone please explain why this is happening? Just FYI, I need to use
sortrows(data,[2,1]);
in my code because the data I've shown here is part of a larger chunk where the values in the second column are different.
Best Answer