How to access Eigen Vector Matrix< float, 2, 1 >

c++, eigen

Solution

If I understand correctly... You can just dereference the iterator to a temporary reference inside the loop for convenience and access coefficients inside like with any `Eigen` object:

for(auto it = uvVertices.begin(); it != uvVertices.end(); ++it) {
    Matrix<float, 2, 1>& v = *it;
    //auto& v = *it; // should also work
    std::cout << v(0,0);  
    std::cout << v(1,0);
}

You could also use range-for:

for(auto& v  : uvVertices) {
    std::cout << v(0,0);  
    std::cout << v(1,0);
}

I would also consider using `Eigen::Vector` type for a vector.

Problem

I am iterating through a vector, which consists of Vector ``` Matrix<float, 2, 1> for(auto it = uvVertices.begin(); it != uvVertices.end(); ++it) { std::cout << *it; } ``` this gives an output like: which works 0.123120.212354 which is correct, how can i access only the first or the second component? So that i get 0.12312 http://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html here is a reference but i could not figur eit out.

Original source