Feature request: Ability to get a "view" into a sub-matrix by indexing it with a vector or matrix of indices
## Submitted by Michael Dixon Assigned to **Nobody** **[Link to original bugzilla bug (#329)](https://eigen.tuxfamily.org/bz/show_bug.cgi?id=329)** ## Description Created attachment 204 A prototype for "views" that would allow Matlab-style indexing of sub-matrices I'd like to be able to index into Eigen matrices with an array of indices, in a way similar to Matlab. I've implemented a prototype of this capability. As a starting point, I've tried to follow the conventions established in Matlab, since I think these will be familiar to many people. I expect that the code I'm posting here will still need some work before it would be suitable for including in the library, but I'm hoping this will help provide a starting point for further discussion. Here's a quick summary of the files in the attachment: include/MyEigen/MatrixViewSubscript.h: implements indexing into a matrix by a set of row indices and a set of column indices. include/MyEigen/MatrixViewIndex.h: implements indexing into a matrix by a single set of indices. This follows the Matlab convention, which allows an element of a 2d matrix to be accessed with a single index (treats the matrix as though it were a vector). include/MyEigen/IndexRange.h: a class for defining ranges of indices, based on a start, and end, and a step size. A negative value for the start or end will define an index relative to the last element of a matrix, with -1 being the last element, -2 being the second to last, and so on. A #define is used to provide shorthand for the common case of IndexRange(0,-1,1) . include/MyEigen/SubToInd.h: a class for combining two matrices containing row and column indices, respectively, into a single set of indices. include/MyEigen/MatrixBaseAddons.h: implements the () operator for various types of indices. include/MyEigen/Core: an include header for including Eigen/Core plus the additional features src/test_views.cpp: a very simple test of the new features **Attachment 204**, "A prototype for "views" that would allow Matlab-style indexing of sub-matrices": [eigenviews.tar.gz](/uploads/aba3bf07aa42568723ec7c2e0bb393c9/eigenviews.tar.gz) ### Depends on #99 #360 ### Blocking #699 #814
issue