Opening the book…
The sort function arranges values in ascending order by default. For a row or column vector, this is straightforward. For a 2D array, MATLAB sorts each column independently.
Using sort
Solution
sortedRowEx =
18 40 66 75 76
sortedColEx =
4
5
10
28
71
sortedArray2 =
29 55 14 26
51 90 14 82
70 96 15 85
To sort in descending order, use the second input argument "descend".
sort(rowEx, 'descend')
This page titled 4.13: Sorting Arrays was last modified on Tue, 30 Jun 2026 02:11:57 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.
The book could not be loaded just now.