简体   繁体   中英

std::vector to Eigen::VectorXf

I have a vector

int N = 100;
std::vector<float> v(N, 1.0f);

which I'd like to convert to an Eigen vector type ( Eigen::VectorXf ?) I have tried

Eigen::VectorXf ev(N);  
ev = Eigen::Map<Eigen::VectorXf>(&v[0], N);

but I am not sure if it right or wrong. I can only see ev has 1 value in my visual studio.

Your code seems correct. No need to initialize ev(N) , though. You can just write

Eigen::VectorXf ev = Eigen::VectorXf::Map(&v[0], N);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM