lettura simple

Submatrix in Octave

In this online lesson I'll explain how to extract a submatrix from a matrix in Octave.

What is a submatrix? It is a matrix with fewer rows and / or columns contained in an initial matrix. For example
an example of a submatrix

I'll give you a practical example

Create a 4x4 matrix

an example 4x4 square matrix

It is a square matrix with four rows and four columns.

$$ M = \begin{pmatrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \\ 13 & 14 & 15 & 16 \end{pmatrix} $$

Extract the first and second columns together with the first and second rows from the matrix M.

square submatrix

The result is a 2x2 square submatrix

the square 2x2 submatrix

Now extract the first three columns along with the first two rows

a submatrix 2x3

The result is a rectangular 2x3 submatrix.

a submatrix 2x3

If you need to extract columns or rows that are not close together, type the columns or rows without the colon as a separator.

For example, extract the first and fourth rows along with the first three columns.

a submatrix 2x3

The result is another 2x3 submatrix of the M.

submatrix 2x3

Note. When you select the columns / rows one by one in square brackets you must separate them with a space or a comma. You can also select multiple rows or columns between the square brackets. For example, the first, third and fourth rows with the first three columns.
matrix 3x3




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin