Data Sorting in MATLAB

Data sorting techniques are often used in data processing programs. MATLAB provides a special function that is 'sort' to do sorting. Using 'sort' can be in two ways. The first way is used to sort the data in the column, its syntax as follows:

var2 = sort(var1,1)

var1 is the matrix or vector to be sorted. Here's how to use it in the program:
>> a=[2 5 7; 7 5 1; 8 7 5]
a =

     2     5     7
     7     5     1
     8     7     5

>> b = sort(a,1)
b =

     2     5     1
     7     5     5
     8     7     7

The second way is used to sort the data on the direction of the line, its syntax as follows:
 >> a=[2 5 7; 7 5 1; 8 7 5]
a =

     2     5     7
     7     5     1
     8     7     5

>> b = sort(a,2)
b =

     2     5     7
     1     5     7
     5     7     8

Data Orientation and Augmentation

Changing the data and put data is very commonly used in the program.. In the other programming language it may be quite difficult. But of course in MATLAB it becomes very easy.

-Changing the orientation of the data by the transpose
>> x = [1 3 5; 2 4 6]
x =

1     3     5
2     4     6

>> x = x'
x =

1     2
3     4
5     6

-Put data on the line.
>> x = [1 3 5;2 4 6]
x =

     1     3     5
     2     4     6

>> y = [7 7 7]
y =
    7     7     7

>> aug = [x;y]
aug =
     1     3     5
     2     4     6
     7     7     7

-Put data on the Column
>> x = [1 3 5; 2 4 6]
x =
     1     3     5
     2     4     6

>> y = [5;5]
y =
    5
    5

>> aug = [x y]
aug =
    1    3    5   5
    2    4    6   5

How to Build Data in MATLAB

In some cases common programs use the initials of data in the form of a matrix or array, such as zero matrix, identity matrix and others. Simply MATLAB provides several techniques to build data quickly, as follows:

-Building data-elements that have been determined.
For example you will build the data x with a known value, then the way of writing as follows:
i. row vector data:
>> x = [1 3 5]
x =
     1 3 5

ii. column vector data
 >> x=[1;3;5]
x =
    1
    3
    5

iii. for the data matrix form
 >> x = [1 3 5;2 4 6]
x =
    1   3   5
    2   4   6

-Build data with initial boundary and final boundary.
Suppose you want to create a data point from the point of 10 degrees to 15 degrees, then the way the writing is as follows:
>> ang = [10:15]
ang =
    10 11 12 13 14 15

-Establish initial boundary data, increment and final boundary
Suppose you want to create a data point from the point of 10 to 50 degrees with a 10 increase, then the way its writing is as follows:
 >> ang = [10:10:50]
ang =
     10   20   30    40    50

-Establish initial boundary data and the deadline, but the amount of data specified
Suppose you want to make 5 pieces of data in the interval angle angle 30 degrees to 70 degrees, then the way his writing is as follows:
 >> ang = linspace(30,70,5)
ang =
     30  40  50  60  70

-Building a logarithmic data with initial boundary and final boundary, but the amount of data specified.
Suppose you want to create 5 data values within the interval 10 and 100, then the way is as follows:
>> y = logspace(1,2,5)
y =
    10.0000   17.7828   31.6228   56.2341  100.0000

-Establish data using standard MATLAB matrix
How to create a data matrix with all elements of value 1:
 >> x = ones(2,3)
x =
    1   1   1
    1   1   1

Create a data matrix with all elements of value 0;
>> x  =  zeros(2,3)
x =
    0   0   0
    0   0   0

Making identity matrix of data, do the following:
 >> x  =  eye(2,2)
x =
   1   0
   0   1

-Building Data-Random
Random data is very often used in programming, particularly the field of mathematical modeling. MATLAB provides a quick way to generate random data as follows:
>> x  =  rand(3,3)
x =
    0.9501    0.4860    0.4565
    0.2311    0.8913    0.0185
    0.6068    0.7621    0.8214

Seen that the generated random data is in the interval 0 and 1. Then how to generate random data with other intervals, such as intervals 2 and 4?

Here is syntax to generate data with random intervals:
variable = (end-(rand () * (end-start)))

Example of usage in the program are as follows:
>> x  =  (4-(rand(3)*(7-5)))
x =

    3.1106    2.1564    3.1886
    2.7691    2.5236    2.1291
    2.4161    3.6475    2.1662