sort the matrix according to order of column

1 次查看(过去 30 天)
Let's say, I have the matrix:
A=[x,y]=[1.1 2;1.2 4;1 4;1.1 3 ;1.3 2;1.3 4;1 2;1.2 3;1.3 3;1.2 2;1 3;1.1 4];
As you observed that:the value of
1st column vary from 1 to 1.3
2nd colume vary from 2 to 4
How can I sort the matrix A to get the result as:
Result=[1 2
1.1 2
1.2 2
1.3 2
1.1 3
1.2 3
1.3 3
1.1 4
1.2 4
1.3 4]

采纳的回答

Guillaume
Guillaume 2018-11-21
编辑:Guillaume 2018-11-21
Result = sortrows(A, [2 1]) %sort first by 2nd column, then by 1st

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by