lefe
lefe

Reputation: 157

How to fill an Eigen Vector with another Eigen Vector?

I have a defined Eigen vector1 and an undefined Eigen vector2, how do i fill vector2 with values of vector1 and subsequent data (doubles) like:

Eigen::RowVectorXd vector1 = Eigen::RowVectorXd::Ones(1);
Eigen::RowVectorXd vector2;
vector2 << vector1, 2.0, 3.4 // Gives AssertionError

Upvotes: 2

Views: 754

Answers (1)

RHertel
RHertel

Reputation: 23788

The << operator can only be used to fill an Eigen::Vector if its size corresponds to that of the supplied data. You could either declare the vector with the correct dimension

Eigen::RowVectorXd vector2(vector1.size() + 2);

or resize it

vector2.resize(vector1.size() + 2);

before using the << operator to fill in the values.

Upvotes: 2

Related Questions