std::vector转eigen矩阵
时间: 2023-10-17 12:31:12 浏览: 212
ros-melodic-eigen-stl-containers:ros-melodic-eigen-stl-containersAUR软件包
要将`std::vector`转换为Eigen矩阵,可以使用`Eigen::Map`函数。首先,需要创建一个`Eigen::VectorXd`对象,并使用`Eigen::Map`将其与`std::vector`关联起来。具体代码如下所示:
```cpp
std::vector<double> vec = {1.0, 2.0, 3.0}; // 假设有一个 std::vector<double>
Eigen::VectorXd eigenVec = Eigen::Map<Eigen::VectorXd, Eigen::Unaligned>(&vec<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Eigen::vector与std::vector的相互转换](https://blog.csdn.net/github_39582118/article/details/120309991)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [Eigen: 一维Vector转为矩阵或者向量](https://blog.csdn.net/u011521131/article/details/77862431)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文