MATLAB技巧 您所在的位置:网站首页 matlab按第一行排序 MATLAB技巧

MATLAB技巧

#MATLAB技巧| 来源: 网络整理| 查看: 265

MATLAB技巧—sort和sortrows函数

2017-03-27

379

MATLAB技巧—sort和sortrows函数

1、sort函数

sort函数用于对数据进行排序,通过help sort命令,可以查找到sort函数的具体用法: Y = SORT(X,DIM,MODE) has two optional parameters.   DIM selects a dimension along which to sort. MODE selects the direction of the sort    'ascend' results in ascending order    'descend' results in descending order The result is in Y which has the same shape and type as X. 上面的意思是说,在sort函数中,有两个参数,一个参数是dim,dim表示的是按照哪一维排序,如行为1,列为2;第二个参数是mode,mode表示的是按照降序或者升序排列(缺省的时候是升序排列)。 对于矩阵 按行升序: 按列升序: 从上述的结果看出,sort函数会比较矩阵中的每一个元素,将行中的每一个元素或者列中的每一个元素按照升序排列。 若现在需要将矩阵按照行排序,可以任意指定排序比较的列。可以使用sortrows函数。 2、sortrows函数 SORTROWS(X,COL) sorts the matrix based on the columns specified in the vector COL.  If an element of COL is positive, the corresponding column in X will be sorted in ascending order; if an element of COL is negative, the corresponding column in X will be sorted in descending order. For example, SORTROWS(X,[2 -3]) sorts the rows of X first in ascending order for the second column, and then by descending order for the third column.

sortrows函数根据列col升序排序:

完 谢谢观看

上一篇: 图论在大数据分析中的作用! ... 下一篇: CDA认证再升一档!与国家共同推进大数 ...

数据分析师,机器学习 ​ 分享 收藏 微信二维码 相关课程学习[点击了解]

相关阅读

CDA认证再升一档!与国家共同推进大数据人才培养标准教育 ... 企业如何利用商品推荐的大数据来破除实体寒冰? ... CDA认证再升一档!与国家共同推进大数据人才培养标准教育 ... Excel-漏斗图分析(差异分析) 3个步骤+1个模型,「数据分析」才是「增长黑客」的核心技 ... 关于机器学习中需要我们知道的事情 中英文垃圾短信过滤 银行数据宽表构建和描述分析


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有