> Financial Mathematics
>> MATLAB Programming
>>> MATLAB Arrays

MATLAB Arrays

Creating Vectors (or one dimensional arrays) in Matlab.

One dimensional array (Vector)


>> X = [1 3 0 -1 5] (press Enter)
ans =
     1 3 0 -1 5

It will create a vector with entries 1 3 0 -1 5




>> X (1) (press Enter)
ans =
     1

It shows the first element of the vector X.




>> X (2) (press Enter)
ans =
     3

It shows the second element of the vector X.




>> X (5) (press Enter)
ans =
     5

It shows the fifth element of the vector X.




>> X (1:3) (press Enter)
ans =
     1 3 0

It shows the elements from first to third of the vector X.




>> X (2:5) (press Enter)
ans =
     3 0 -1

It shows the elements from second to fifth of the vector X.



Size of an array


>> size (X) (press Enter)
ans =
     1 5

It shows size of the array X (1 row and 5 columns).

Next: Matrix in Matlab