Array and Matrix

Parent Previous Next

Array and Matrix


An array is defined by


[Scalar, Scalar, Scalar, Scalar, ..., Scalar]


An 1D array is usually considered same as a row vector or a matrix with only one row.


An matrix is defined as


[Row; Row; Row; Row; ...; Row]


where Row is defined as


Scalar, Scalar, Scalar, Scalar, ..., Scalar


Each of the matrix rows must contains the same number of scalar elements.


After the vector is assigned to a variable, the value of an element of the vector can be accessed by


VECTOR_NAME[i]


where i is the indices of the array.


The specified element of the vector can also be assigned to another value by


VECTOR_NAME[i] = value


You can also extract sub-vector from a matrix by


VECTOR_NAME[i1:i2]


where i1i2 is the indices range in the vector.


After the matrix is assigned to a variable, the value of an element of the matrix can be accessed by


MATRIX_NAME[i, j]


which i is the row number and j is the column number of the matrix.


The specified element of the matrix can also be assigned to another value by


MATRIX_NAME[i, j] = value


You can also extract sub-matrix from a matrix by


MATRIX_NAME[i1:i2, j1:j2]


where i1i2 is the indices range in rows and j1j2 is the indicies range in column.


If a symbol ":" is used for the indices of vector or matrix, it means the range is the whole length of elements for the vector or number of rows/columns for the matrix.


The following are some examples


Input

Output

a = [1,2,3,4,5]

a[2]

a[2:4]

a[3:]

a[:2]

a[:]

a[3] = 0

A=[1,2,3;4,5,6]

A[2,3]

A[1, 2:3]

A[:, 2:3]

A[1:2,2:3]

A[1]

A[1:2]

A[2,2] = 0


Tips


Created with the Personal Edition of HelpNDoc: Full-featured Documentation generator