Indexing Vectors

An array of dimension 1 x N is called a row vector.The elements of such a vector can be accessed using a single index value (also called a subscript). Thus, v (1 ) is the first element of vector v, v (2) is its second element, and so forth. Vectors can be formed in MATLAB by enclosing the elements, separated by spaces or commas, within square brackets.

Example

>> A = [1 2 3 4 5 6]

A =

     1     2     3     4     5     6

Accessing vector elements

Example

>> A(1)

ans =

     1

>> A(3)

ans =

     3

>> A(3) = 6

A =

     1     2     6     4     5     6

>> A(3)

ans =

     6