Sorting rows by column 1, and then sorting each subset of column 1 by column 2... i.e sort so X coordinates are ascending and then sort all values with the same X by Y

2 views (last 30 days)
Hi all,
i have a point cloud stored as a 2D matrix, that is arranged as follows:
[X1, Y1, Z1;
X2, Y2, Z2;
X3, Y3, Z3;
X4, Y4, Z4;
X5, Y5, Z5;
.........]
I need to order it in terms of X first so have used sortrows(ARRAY,1)
but i now need to sort the subsiquent array in terms of Y, so for example if 5 X coordinates are the same, it would order them in terms of Y:
-0.9793 19.6374 -0.4139
-0.9793 19.7048 -0.2340
-0.9793 19.7351 -0.4889
-0.9793 19.8851 -0.2104
-0.9793 19.7237 -0.2300
-0.9793 19.6427 -0.4213
-0.9793 19.6195 -0.2687
-0.9793 19.7797 -0.2203
-0.9793 20.1755 -0.3784
-0.9793 19.6788 -0.4635
-0.9792 19.6477 -0.4281
-0.9792 20.1513 -0.4128
-0.9792 19.6024 -0.2839
-0.9792 20.1289 -0.4351
-0.9792 20.1161 -0.2207
-0.9792 20.1566 -0.2360
-0.9792 19.9529 -0.2074
-0.9792 20.1677 -0.3921
-0.9792 20.0403 -0.4777
These would then be ordered in terms of Y, whilst preserving the X coordinates if that makes sense....
I'd appreciate any help!
Regards, Ben

Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!