Problems with sortrows function
I am trying to sort a two dimensional matrix Coord consisting of (x,y) pairs of coordinates (of size n x 2) in lexicographical order, with respect to x and then y. I used the command
[Coord_Lex,ix]=sortrows(Coord,[1,2]);
This should sort x coordinates in ascending order and within each set of matrix rows with the same x coordinate the y coordinates in ascending order. But in some cases it does not work correctly. For example, a part of the answer that I am getting is
1.2250 0.2067
1.2250 0.1722
1.2250 0.1378
1.2250 0.1033
1.2250 0.0689
1.2250 0.0344
1.2250 -0.2933
1.2250 -0.3278
1.2250 -0.3622
1.2250 -0.3967
1.2250 -0.4311
i.e., the y coordinaes are not sorted correctly. I checked the values of x coordinates in the incorrect part for the round-off error polution and the difference between them always gives 0.I am trying to sort a two dimensional matrix Coord consisting of (x,y) pairs of coordinates (of size n x 2) in lexicographical order, with respect to x and then y. I used the command
[Coord_Lex,ix]=sortrows(Coord,[1,2]);
This should sort x coordinates in ascending order and within each set of matrix rows with the same x coordinate the y coordinates in ascending order. But in some cases it does not work correctly. For example, a part of the answer that I am getting is
1.2250 0.2067
1.2250 0.1722
1.2250 0.1378
1.2250 0.1033
1.2250 0.0689
1.2250 0.0344
1.2250 -0.2933
1.2250 -0.3278
1.2250 -0.3622
1.2250 -0.3967
1.2250 -0.4311
i.e., the y coordinaes are not sorted correctly. I checked the values of x coordinates in the incorrect part for the round-off error polution and the difference between them always gives 0. I am trying to sort a two dimensional matrix Coord consisting of (x,y) pairs of coordinates (of size n x 2) in lexicographical order, with respect to x and then y. I used the command
[Coord_Lex,ix]=sortrows(Coord,[1,2]);
This should sort x coordinates in ascending order and within each set of matrix rows with the same x coordinate the y coordinates in ascending order. But in some cases it does not work correctly. For example, a part of the answer that I am getting is
1.2250 0.2067
1.2250 0.1722
1.2250 0.1378
1.2250 0.1033
1.2250 0.0689
1.2250 0.0344
1.2250 -0.2933
1.2250 -0.3278
1.2250 -0.3622
1.2250 -0.3967
1.2250 -0.4311
i.e., the y coordinaes are not sorted correctly. I checked the values of x coordinates in the incorrect part for the round-off error polution and the difference between them always gives 0. sortrows MATLAB Answers — New Questions