查看完整版本 : [求助]关于matlab排序的问题!
我知道能用 sort排一个矩阵的序,但是只能是对某一列,我现在想按其中一列排序,然后其他的列与排序 的列的相对位置不变,怎么半啊???有没这样的命令??没有该怎么做呢??
比如要对【2,3,1;4,5,6】按第一列排序后是【1,2,3;6,4,5】
谢谢大家啊!!
很简单,你复制代码运行下:
a=[2,3,1;4,5,6];
[b,pos]=sort(a(1,:));
a=a(:,pos);
a
用sortrows函数,自己看帮助,
B = sortrows(A,column) sorts the matrix based on the columns specified in the vector column. If an element of column is positive, the MATLAB? software sorts the corresponding column of matrix A in ascending order; if an element of column is negative, MATLAB sorts the corresponding column in descending order. For example, sortrows(A,[2 -3]) sorts the rows of A first in ascending order for the second column, and then by descending order for the third column.
vBulletin® v3.8.3,版权所有 ©2000-2025,Jelsoft Enterprises Ltd.