Monday, 1 August 2016

MATLAB Programming 43 - Sorting of arrays


Sorting Arrays


Create a script file and type the following code into it:


v = [ 23 45 12 9 5 0 19 17]      % horizonal vector
sort(v)      %sorting v
m = [2 6 4; 5 3 9; 2 0 1]      % two dimensional array
sort(m, 1)      % sorting m along the row
sort(m, 2)      % sorting m along the column

When you run the file, it displays the following result:


v =
23 45 12 9 5 0 19 17

ans =
0 5 9 12 17 19 23 45

m =
2 6 4
5 3 9
2 0 1

ans =
2 0 1
2 3 4
5 6 9

ans =
2 4 6
3 5 9
0 1 2


No comments:

Post a Comment