简体   繁体   中英

Slicing and Indexing Eigen matrix Error: how to index matrix correctly?

I have matrix u with size 11 by 15 where 11 is number of rows and 15 number of columns. I am trying to index my matrix so that the first five columns and the last five columns are equal to some expression. I am able to index the first 5 columns but not last 5 as the following:

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

The second indexing is incorrect, and it resturns the 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.

How can I index this properly.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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