I did a `MATLAB` code and it had to perform
B2=abs(B2/max(B2));
where `B2` is an `n x m` matrix . What should be the equivalent `C++` code using Eigen library? Please help.
On modifying my code
//problem
#include <iostream>
#include<complex.h>
#include <eigen3 eigen="" dense="">
#include <eigen3 eigen="" core="">
using namespace Eigen;
using namespace std;
using Eigen::MatrixXd;
int main()
{
MatrixXd A(2,2);MatrixXd B(2,1);MatrixXd C(1,2);
A<<4,12,
6,8;
C=A.colwise().maxCoeff();
//B=(A*(1.0/C)).cwiseAbs();
B=A.array()/C.array();
cout << "The solution is A :\n" << B.cwiseAbs()<< endl;
return 0;
}
What I have tried:
But I am not able to execute this code.
hp@hp-HP-Notebook:~/beamforming/programs/eigen_prog$ g++ mm_t.cpp -o mm_t
hp@hp-HP-Notebook:~/beamforming/programs/eigen_prog$ ./mm_t
mm_t: /usr/local/include/eigen3/Eigen/src/Core/CwiseBinaryOp.h:110: Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::CwiseBinaryOp(const Lhs&, const Rhs&, const BinaryOp&) [with BinaryOp = Eigen::internal::scalar_quotient_op<double, double>; LhsType = const Eigen::ArrayWrapper<Eigen::Matrix<double, -1, -1> >; RhsType = const Eigen::ArrayWrapper<Eigen::Matrix<double, -1, -1> >; Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::Lhs = Eigen::ArrayWrapper<Eigen::Matrix<double, -1, -1> >; Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::Rhs = Eigen::ArrayWrapper<Eigen::Matrix<double, -1, -1> >]: Assertion `aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols()' failed.
Aborted (core dumped)
Any idea what is wrong?? Please help.