
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

I'll give you a practical example
Create a 4x4 matrix

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

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

The result is a 2x2 square submatrix

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

The result is a rectangular 2x3 submatrix.

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.

The result is another 2x3 submatrix of the M.

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.


