简体   繁体   English

按索引设置特征矩阵/向量

[英]Setting Eigen Matrix/Vector by index

How exactly do we set the value of an Eigen Vector or Matrix by index.我们如何通过索引设置特征向量或矩阵的值。 I'm trying to do something similar to:我正在尝试做类似的事情:

// Assume row major
matrix[i][j] = value
// or
vector[i] = value

I might have missed it, but could not find anything in the quick reference guide .我可能错过了,但在快速参考指南中找不到任何内容。

As pointed out by user chtz, the problem is the usage of the 'auto' keyword which is further explained on the Eigen website here.正如用户 chtz 所指出的,问题在于“auto”关键字的使用,此处的Eigen 网站对此进行了进一步解释。

Both of the following:以下两者:

// Assume row major
matrix(i,j) = value
// or
vector(i) = value

should work correctly.应该可以正常工作。 I did test on the VectorXf and it indeed works correctly.我在 VectorXf 上进行了测试,它确实可以正常工作。

Block operation is one choice:块操作是一种选择:

Eigen::Vector4f diag_Vec(1, 2, 4, 7);
Eigen::Matrix4f Mat = diag_Vec.matrix().asDiagonal();
Mat.block<1, 1>(2, 3) = Eigen::Matrix<float, 1, 1>(-4.5);
Mat.block<1, 1>(3, 2) = Eigen::Matrix<float, 1, 1>(1);
cout << "Mat: \n" <<Mat << endl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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