# 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.

A=\begin{pmatrix} 5 & 7 & 8 \\ 4 & 6 & 1 \\ 8 & 0 & 7 \end{pmatrix}

## 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升序排序：

297 篇文章60 人订阅

0 条评论

## 相关文章

13510

32730

27020

### Q152 Maximum Product Subarray

Find the contiguous subarray within an array (containing at least one number) wh...

43370

11210

### 25:最长最短单词

25:最长最短单词 总时间限制: 1000ms 内存限制: 65536kB描述 输入1行句子（不多于200个单词，每个单词长度不超过100），只包含字母、空格...

398100

### 06:笨小猴

06:笨小猴 总时间限制:1000ms内存限制:65536kB描述 笨小猴的词汇量很小，所以每次做英语选择题的时候都很头疼。但是他找到了一种方法，经试验证明，用...

34070

72590

44150

8210