I want to find the maximum values ββand indices on a row of a matrix. I based this on an example on my own website (Example 7).
#include <iostream> #include <Eigen/Dense> using namespace std; using namespace Eigen; int main() { MatrixXf mat(2,4); mat << 1, 2, 6, 9, 3, 1, 7, 2; MatrixXf::Index maxIndex; VectorXf maxVal = mat.rowwise().maxCoeff(&maxIndex); std::cout << "Maxima at positions " << endl; std::cout << maxIndex << std::endl; std::cout << "maxVal " << maxVal << endl; }
The problem here is that my line
VectorXf maxVal = mat.rowwise().maxCoeff(&maxIndex);
wrong. Source example has
float maxNorm = mat.rowwise().sum().maxCoeff(&maxIndex);
i.e. There is an additional abbreviation .sum (). any suggestions? I assume that I just want my own equivalent to be what in matlab I would write as
[maxval maxind] = max(mymatrix,[],2)
i.e. find the maximum value and index by the second size mymatrix and return to the matrix (nrow (mymatrix), 2). thanks!
(also sent to its own list, sorry for cross-mailing.)
source share