Page 25 - MATLAB an introduction with applications
P. 25

10 ———  MATLAB: An Introduction with Applications


                   1.9.4  Addressing Arrays
                   A colon can be used in MATLAB to address a range of elements in a vector or a matrix.

                   1.9.4.1 Colon for a vector
                   Va(:) – refers to all the elements of the vector Va (either a row or a column vector).
                   Va(m:n) – refers to elements m through n of the vector Va.
                   For instance,
                              >> V = [2  5  –1  11  8  4  7  –3  11]
                              >> u = V (2 :8)
                                 u = 5  –1  11  8  4  7  –3  11

                   1.9.4.2 Colon for a matrix
                   Table 1.16 gives the use of a colon in addressing arrays in a matrix.
                                               Table 1.16 Colon use for a matrix
                              Command                          Description
                              A(:, n)   Refers to the elements in all the rows of a column n of the matrix A.
                              A(n, :)   Refers to the elements in all the columns of row n of the matrix A.
                              A(:, m:n)   Refers to the elements in all the rows between columns m and n of
                                        the matrix A.
                              A(m:n, :)   Refers to the elements in all the columns between rows m and n of
                                        the matrix A.
                              A(m:n, p:q)  Refers to the elements in rows m through n and columns p through
                                        q of the matrix A.


                   1.9.5  Adding Elements to a Vector or a Matrix
                   A variable that exists as a vector or a matrix can be changed by adding elements to it. Addition of elements is
                   done by assigning values of the additional elements, or by appending existing variables. Rows and/or columns
                   can be added to an existing matrix by assigning values to the new rows or columns.

                   1.9.6  Deleting Elements
                   An element or a range of elements of an existing variable can be deleted by reassigning blanks to these
                   elements. This is done simply by the use of square brackets with nothing typed in between them.

                   1.9.7  Built-in Functions
                   Some of the built-in functions available in MATLAB for managing and handling arrays as listed in
                   Table 1.17.

















                   F:\Final Book\Sanjay\IIIrd Printout\Dt. 10-03-09
   20   21   22   23   24   25   26   27   28   29   30