Sorting entire matrix according to one column in matlab

前端 未结 2 1119
执笔经年
执笔经年 2020-11-30 10:08

I have the matrix as follows

a =

 1     3
 2     5
 3     2
 4     8
 5     9

I want to sort the second column in the a matri

相关标签:
2条回答
  • 2020-11-30 10:25

    Try this:

    sortrows(a,2)

    This should sort according to the second column.

    0 讨论(0)
  • 2020-11-30 10:25

    or use:

    [val idx]=sort(a(:,2));
    ans = [a(idx,1) val]
    
    0 讨论(0)
提交回复
热议问题