How to extract two or more rows from a matrix in Matlab and Octave
To extract two or more rows of a matrix on Matlab and Octave
In the first parameter indicate the interval a:b between the rows
- term a is the number of the first row to be extracted
- term b is the number of the last row to be extracted
In the second parameter after the comma indicate the symbol : to take all the columns of the matrix
Indicate the list of rows to be extracted in square brackets at the first parameter.
Separate the lines from each other by a space or a comma.
This method allows you to extract even the rows of the matrix that are not close to each other.
Define a 3x2 matrix with three rows and two columns
>> M=[1 2; 3 4 ; 5 6]
Extract the first two rows of matrix M
The command extracts the first and second rows.
Extract the first and third rows of the matrix.
>> M([1 3],:)
The command extracts the first and third rows of the M matrix.