sort( ) command or function arranges vector or matrix or array elements in ascending order, after reading this MATLAB sort topic, you will know the theory and examples.
Syntax:
sort(n)
- n can be a vector or matrix.
Example: To create a vector and arrange all elements in ascending order of a vector.
Output:
n = 1 2 2 10 5 78 ans = 1 2 2 5 10 78Example: To create a matrix and arrange all elements in ascending order for each column of the matrix.
Output:
n = 1 2 3 1 2 23 4 5 21 ans = 1 2 3 1 2 21 4 5 23Explanation:
- sorting of each column elements of the matrix.