Matrices in Matlab

Matrices can be represented conveniently in MATLAB as a sequence of row vectors enclosed by square brackets and separated by semicolons. For example, typing :

Example

>> A = [1,2,3; 4,5,6; 7,8,9]

A =

     1     2     3
     4     5     6
     7     8     9

Example

We select elements in a matrix just as we did for vectors, but now we need two indices: one to establish a row location, and the other for the corresponding column. For example, to extract the element in the second row, third column of matrix A, we write :

>> A(2,3)

ans =

     6