matlab对一列进行排序并在第二列上保留各自的值

Bun*_*lan 2 sorting matlab row

我如何在matlab中进行简单的排序.我总是必须使用excel链接导入我的数据,对其进行排序,然后导出回matlab.这很烦人!

我有一个矩阵<10x10>,我想按降序对第一列进行排序,同时保持第二列的相应值.Matlab似乎只是单独对每列进行排序.

Example:
matrix a
5 4
8 9
0 6
7 3

matrix b (output)
0 6
5 4
7 3
8 9
Run Code Online (Sandbox Code Playgroud)

sfs*_*man 10

sortrows@chaohuang 的答案可能正是你所寻找的.但是,它会根据所有列进行排序.如果您只想根据第一列进行排序,那么您可以这样做:

% sort only the first column, return indices of the sort
[~,sorted_inds] = sort( a(:,1) );

% reorder the rows based on the sorted indices
b = a(sorted_inds,:); 
Run Code Online (Sandbox Code Playgroud)