Using Array Concatenation and Slices

The following usage examples show a few common programming situations where both array concatenation and array slices are involved, and how to do this correctly in order to avoid certain mistakes.

1 Appending an Element to Vectors and Row/Column Matrices

The first equations set XA1, XA2, XA3 and XA4 equal to row matrices and XB1, XB2 equal to column matrices respectively, created by appending an additional element to row/column matrices PA and PB.

1.1 Simulation of AppendElement

Take a look at the value at time=0:

2 Composing a Blocked Matrix Board from Submatrices

The following example shows three very similar ways of constructing a blocked matrix from submatrices. The first two variants follow the rule of always making sure that returned array slices as arguments to the special purpose concatenation operators are matrices. The third variant breaks this rule, since two of the array slices return vectors, causing an error.

2.1 BlockMatrix

2.2 BlockMatrix2

2.3 BlockMatrix3

3 Cyclic Permutation of Matrix Rows or Columns

Cyclic permutation can be achieved by a combination of concatenation operations and array slices or just array slices using a permutation vector.

3.1 Simulation of CyclicPerm