matlab sortrows
时间: 2023-10-16 21:23:30 浏览: 104
The sortrows function in MATLAB is used to sort a matrix or table based on one or more columns. The syntax for the function is:
```matlab
B = sortrows(A, cols)
```
where A is the matrix or table to be sorted, cols is a vector of column indices specifying the order of sorting. For example, if cols = [3 1], the matrix will be sorted first by the values in column 3, and then by the values in column 1.
The output B is a sorted version of A. If A is a matrix, B is also a matrix. If A is a table, B is a table with the same variable names and properties as A.
Here's an example of using sortrows to sort a matrix:
```matlab
A = [5 4 3; 2 1 6; 7 8 9];
B = sortrows(A, [2 1]);
```
In this case, the matrix A is sorted first by column 2, and then by column 1. The result B is:
```
B =
2 1 6
5 4 3
7 8 9
```
阅读全文