Entering vectors

Here, we recall from Chapter 1 a useful method to enter a specific type of vectors. A row vector is in MATLAB a matrix with one row, while a column vector is a matrix with one column. So vectors are entered in the same way as matrices. If the difference between the consecutive elements of the row is the same all the time, the row can also be entered by using

`variable' = `initial value':`step size':`final value'

where `initial value' is the first element of the row, `final value' is the last element of the row, and `step size' is the difference between the consecutive elements. For example:
>> x = 1:-0.2:0

x =
    1.0000    0.8000    0.6000    0.4000    0.2000         0
If the difference between the consecutive elements of the row equals one and the elements should be increasing, you can omit `step size'. For example:
>> x = 1:5

x =
    1     2     3     4     5
To form a column vector, it is often easiest to first form a row vector, and then to transpose this row vector (see also Chapter 1). For example,

» x = [1:5]'

gives the transpose of the row [1 2 3 4 5], i.e.,
x =
    1
    2
    3
    4
    5



Previous      Next      Up      Contents


Esteur 2010-03-22