我想通过垂直堆叠2N x 9
N
矩阵创建2N
大小的矩阵,其中1x9
是动态值。
这是我尝试做的。
using CoefficientMatrix = Eigen::Matrix<T, Eigen::Dynamic, 9>;
using CoefficientRow = Eigen::Matrix<T, 1, 9>;
CoefficientMatrix A(2*N, 9);
for (int i = 0; i < N; i++) {
CoefficientRow ax;
CoefficientRow ay;
// fill in ax and ay
A << ax, ay;
}
但是,我收到以下运行时错误。
Assertion failed: (((m_row+m_currentBlockRows) == m_xpr.rows() || m_xpr.cols() == 0) && m_col == m_xpr.cols() && "Too few coefficients passed to comma initializer (operator<<)"), function finished, file /usr/local/include/eigen3/Eigen/src/Core/CommaInitializer.h, line 120.
[我尝试通过断言语法进行解析,但是不确定我的代码(Eigen的新知识)指的是那些内部变量名称。
感谢您的协助。
operator <<
的重载立即填充整个矩阵。如果尺寸不匹配,则会遇到运行时错误。
以这种方式看。假定代码按您的要求工作(operator <<
插入单行?一次插入两行?)。两次连续呼叫operator <<
如何工作?现在是否每个矩阵都必须跟踪operator <<
被调用了多少次?或者相反,如果插入了部分行,应如何处理?
TLDR:编写类似这样的内容: