切片和索引特征矩阵错误:如何正确索引矩阵?



我有矩阵u,大小为11 × 15,其中11为行数,15为列数。我试着索引我的矩阵使前五列和后五列等于某个表达式。我能够索引前5列,但不能索引后5列,如下所示:

static const int nx = 10;
static const int ny = 10;
static const int mm = nx* 3/2;
Eigen::Matrix<std::complex<double>, (ny+1), mm> u;
u.setZero();
u(all,seqN(0,nx/2)) 
u(all,seqN(last-nx/2,last)) //ERROR

第二个索引不正确,它返回错误:

Eigen::Block<XprType, BlockRows, BlockCols, InnerPanel>::Block(XprType&, Eigen::Index, Eigen::Index, Eigen::Index, Eigen::Index) [with XprType = Eigen::Matrix<std::complex<double>, 11, 15>; int BlockRows = 11; int BlockCols = -1; bool InnerPanel = true; Eigen::Index = long int]: Assertion `startRow >= 0 && blockRows >= 0 && startRow <= xpr.rows() - blockRows && startCol >= 0 && blockCols >= 0 && startCol <= xpr.cols() - blockCols' failed.

我怎样才能正确地索引这个

感谢@chtz的评论,这解决了这个问题:

seq(last+1-nx/2, last)

最新更新