I'm very new in c++ but this code works in may application.
It works only for full dynamic matrixs but can adapt it.
If anyone has a better way please show me i really want to learn.
template<typename ScalarType>
void MatrixXdRemoveCol(Eigen::Matrix<ScalarType,-1,-1,0,-1,-1> *mat, int colindex)
{
Eigen::Matrix<ScalarType,-1,-1,0,-1,-1> *auxmat = new Eigen::Matrix<ScalarType,-1,-1,0,-1,-1>;
*auxmat = *mat;
mat->resize(mat->rows(),mat->cols()-1);
int rightColsSize = auxmat->cols()-colindex-1;
mat->leftCols(colindex) = auxmat->leftCols(colindex);
mat->rightCols(rightColsSize) = auxmat->rightCols(rightColsSize);
}
template<typename ScalarType>
void MatrixXdRemoveCols(Eigen::Matrix<ScalarType,-1,-1,0,-1,-1> *mat, std::vector<int>* cols)
{
for(auto iter = cols->rbegin();iter != cols->rend();iter++)
MatrixXdRemoveCol<ScalarType>(mat,*iter);
}
template<typename ScalarType>
void MatrixXdRemoveRow(Eigen::Matrix<ScalarType,-1,-1,0,-1,-1> *mat, int rowindex)
{
Eigen::Matrix<ScalarType,-1,-1,0,-1,-1> *auxmat = new Eigen::Matrix<ScalarType,-1,-1,0,-1,-1>;
*auxmat = *mat;
mat->resize(mat->rows()-1,mat->cols());
int BottomRowsSize = auxmat->rows()-rowindex-1;
mat->topRows(rowindex) = auxmat->topRows(rowindex);
mat->bottomRows(BottomRowsSize) = auxmat->bottomRows(BottomRowsSize);
}