Creation, Access and Modification

We are showing here how to create vectors and matrices and how to access and modify their values.

Creation

Creating a row vector with 3 values can be done using brackets:

>> v = [6 3 1 5]#

     6     3     1     5

In order to create a matrix with multiple rows we can use semi-colons to delimit rows. Let's create a matrix with 3 rows and 3 columns:

>> m = [5 8 0; 2 -1 -2; 3 6 7]#

     5     8     0
     2    -1    -2
     3     6     7

Access

The most common way of accessing values from mathlayer® variables is through the parentheses operator.

For instance, in order to access the third element in vector v:

>> v(3)#

 1

or to access the element in third row, second column of matrix m:

>> m(3,2)#

 6

which can be equivalently accessed using a single subscript based on column-major order:

>> m(6)#

 6

Modification

Modifying values is as straightforward as accessing them. To modify the third element in vector v with a value of 10 (note that the entire vector is displayed in this case):

>> v(3) = 10#

     6     3     10     5

To modify the element in third row, second column of matrix m, also with a value of 10:

>> m(3,2) = 10#

     5     8     0
     2    -1    -2
     3    10     7

or equivalently:

>> m(6) = 10#

     5     8     0
     2    -1    -2
     3    10     7