如何获取Eigen::MatrixXd的行数和列数
How to get the number of rows and columns of an Eigen::MatrixXd?
我正在尝试遍历Eigen::MatrixXd matrix
。但是,似乎没有返回列大小和行大小的函数。有人知道怎么做吗?
这应该有效。。。
#include <Eigen/Dense>
int main()
{
Eigen::MatrixXd matrix(3, 4);
// An explicit cast required on rows() and
// cols() to convert the output type of
// Eigen::Index into int
int r = static_cast<int>(matrix.rows());
int c = static_cast<int>(matrix.cols());
for (int i = 0; i < r; ++i)
{
for (int j = 0; j < c; ++j)
{
std::cout << matrix(i,j) << " ";
}
std::cout << std::endl;
}
return 0;
}
与@Icarus3相同的答案,但没有警告:
#include <Eigen/Dense>
int main()
{
Eigen::MatrixXd matrix(3, 4);
auto const rows = matrix.rows();
auto const cols = matrix.cols();
for (Eigen::Index i{0}; i < rows; ++i) {
for (Eigen::Index j{0}; j < cols; ++j) {
std::cout << matrix(i, j) << " ";
}
std::cout << "n";
}
std::cout << std::endl;
return 0;
}
相关文章:
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- 将 MatrixXd 的行传递给要修改的函数,而不在 Eigen 中创建副本
- 如何获取Eigen::MatrixXd的行数和列数
- 将 Eigen::MatrixXd 转换为 arma::mat 并在新对象上制作副本
- 将 Eigen::MatrixXd 矩阵转换为 cgal 容器类型
- Eigen:将真实和想象的MatrixXd映射到MatrixXcd
- Eigen::MatrixXd.block assignment using a std::vector
- eigen C 不能反向matrixxd
- 关于 Eigen::MatrixXd 逐列计算的问题
- 将eigen :: arrayxxd转换为eigen :: matrixxd
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- Un-flatten Eigen::VectorXd to Eigen::MatrixXd
- c++ lambda 函数,用于将 Eigen::VectorXd 转换为 Eigen::MatrixXd
- C :如何将std ::向量转换为eigen :: matrixxd
- 指向eigen matrixxd的子行,表现得像vectorxd
- 将数据从 std::vector 复制到 Eigen's MatrixXd in C++
- 从 Eigen::CwiseBinaryOp 转换为 MatrixXd 会导致段错误
- Eigen MatrixXd作为返回类型
- 使用 Eigen::Map<Eigen::MatrixXd> 作为 Eigen::MatrixXd 类型的函数参数
- 如何捕获 Eigen 的 MatrixXd::resize() 函数引发的异常?