MATLAB技巧——sort和sortrows函数
来源:互联网 发布:mac photoshop 编辑:程序博客网 时间:2024/06/06 03:40
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 orderThe 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 thevector COL. If an element of COL is positive, the corresponding columnin 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 thirdcolumn.
sortrows函数根据列col升序排序:
0 0
- MATLAB技巧——sort和sortrows函数
- Matlab学习笔记(6)——sort和sortrows对矩阵排序
- Matlab sortrows函数
- matlab2c使用c++实现matlab函数系列教程-sortrows函数
- matlab sortrows函数 对行进行排序
- matlab中sortrows的用法
- matlab中的sort函数
- matlab中的sort函数 .
- matlab中的sort函数
- MATLAB中的sort函数
- matlab中的sort函数
- matlab中的sort函数
- MATLAB中的sort函数
- matlab sort函数
- 【matlab】利用sortrows进行Z字形扫描
- MatLab的排序函数-sort .
- Matlab的排序函数-sort
- matlab中的sort函数详解
- LeetCode 52. N-Queens II
- H.264 sequence parameter sets成员值含义学习笔记
- php复习 第十天 图形操作3之等比例缩放
- hdu2995
- shiro简介,认证,认证流程,自定义realm,散列算法
- MATLAB技巧——sort和sortrows函数
- java 中的Cloneable 接口
- H.264 picture parameter sets成员值含义学习笔记
- 面试题----统计水果出现次数最多的前三名(map的运用)
- EL表达式 (详解)
- centos 7安装mysql5.5和安装 mariadb 的正确命令
- 快速排序与随机化快排运行速度实验比较
- js系统5秒后自动返回
- scala开发spark应用程序