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