Entering matrices

A matrix can be entered in different ways:
  1. Between [ and ], where the rows are separated by a semicolon, and the elements are separated by spaces or commas. For example:

    >> A = [1 2 3;4 5 6;7 8 9]
    or
    >> A = [1,2,3;4,5,6;7,8,9]
  2. Between [ and ], where every row starts on a new line and the elements are separated by spaces or commas. For example:

    >> A = [1 2 3
    4 5 6
    7 8 9]
  3. Via external files in which the values of the variables are stored or are being calculated.
A matrix element can consist of all MATLAB elements. For example, the command:

>> a = [-1.3 sqrt(3) (1+2+3)*4/5]

You can also build a matrix out of other matrices to form a new matrix. For example,

C = [A;a]

produces matrix

$\displaystyle C= \begin{bmatrix}A \\ a \end{bmatrix}.$ (4.1)

When doing this, the sizes of the matrices have to be compatible!



Previous      Next      Up      Contents


Esteur 2010-03-22