How can I access a single vector from a matrix?
For example: Is there a way to extract a vector using something like A(i)
for a matrix Eigen::MatrixXf A(10,10)
that returns an Eigen::VectorXf A(10)
?
As mentioned above, in Eigen, vectors are just a special case of matrices, with either 1 row or 1 column. The case where they have 1 column is the most common; such vectors are called column-vectors, often abbreviated as just vectors.
Matrix is a 3 × 1 matrix. It has rows and column. Thus, it is a column vector.
The default in Eigen is column-major.
To get a specific column of a matrix, specify the column number preceded by a comma, in square brackets, after the matrix variable name. This expression returns the required row as a vector.
Found in the documentation :/ The way to access a single column is .col(i)
, and similarly for row, its .row(i)
. Also of interest is .block<>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With