Use the
sort, reverse, csort, and
rsort functions for arranging elements of an array in ascending or descending order. You may need to sort arrays for the interpolation and regression functions that require sorted inputs.
1. Define a vector to be sorted.
2. Sort vector x in ascending order.
3. Sort vector x in descending order.
4. Define a data set.
5. Use the csort function to sort the values of the second column of M in ascending order, while maintaining the relationship between the entries in the first and second columns.
6. Use sorting to visually examining your data before further analysis, for example, to decide how many bins to request on a histogram.
7. Plot column 1 of sunhist versus column 0.
8. Create a 3 column matrix by augmenting M with matrix A.
9. Use the rsort function to rearrange the columns of R so that the specified row is in ascending order, while maintaining the relationship between the entries in all columns.
The top 10 rows are already in ascending order, thus the result of rsort (the order of the columns) is identical for rows 0-9.
Row 10 (6, 3, 1710) is the first row that needs to be rearranged in ascending order, thus the order of the columns is changed accordingly to have (3, 6, 1710) in row 10.