Matrices and vectors in MatLab

The Mat part of MatLab stands for matrix. All variables in MatLab are considered to be matrices. Scalar variables are really 1x1 matrices so far as MatLab is concerned. Vector variables are either Nx1 matrices (column vectors) or 1xN matrices (row vectors). And matrix variables are MxN matrices. When two matrix or vector variables in MatLab are multiplied, they must have row and column dimensions that are compatible for matrix multiplication. That is, the first variable must have dimensions MxN and second must have NxQ. If this is not the case and you try to multiply the two matrices, then MatLab will respond with an Mpower error statement.

To save (assign) this matrix to the name A, execute the statement A = [1 3 4 ; 3 2 3 ; 5 1 2]

Values within the same row are separated with spaces or commas, and rows are separated with semicolons. So the first three numbers are in the first row, and so on.

To access (use) individual elements of variables in MatLab, use this syntax:

    matrixName( vectorOfRowNumbers, vectorOfColNumbers )
        A(1,1) % gets row 1, column 1 which is the value  1
        A(1,2) % gets row 1, column 2 which is the value  3
        …
        A(3,2) % gets row 3, column 2 which is the value  1
        A(3,3) % gets row 3, column 3 which is the value  2
        A([1 2],3) % gets rows 1 and 2, column 3 which is the values 4 and 3 in a column
    

A column vector can be entered as C = [2 ; 3 ; 1];

The transpose operator in linear algebra switches the rows to columns

In MatLab the transpose operator is the apostrophe character. It is placed immediately after the matrix to be transposed.