I did a MATLAB code and it had to perform
B3=abs(B2/max(B2));
where B2 is an 181 x 238 matrix , max(B2) should give me a matrix of 1 x 238 comprising of maximum value in each column and B3 should be 181x1matrix. What should be the equivalent C++ code using Eigen library? Please help.
On modifying my code, with simpler dimension say with 2 x 2 matrix
//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;
}
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::CwiseBinaryOp(const Lhs&, const Rhs&, const BinaryOp&) [with BinaryOp = Eigen::internal::scalar_quotient_op; LhsType = const Eigen::ArrayWrapper >; RhsType = const Eigen::ArrayWrapper >; Eigen::CwiseBinaryOp::Lhs = Eigen::ArrayWrapper >; Eigen::CwiseBinaryOp::Rhs = Eigen::ArrayWrapper >]: Assertion `aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols()' failed. Aborted (core dumped)
Any idea what is wrong?? I did simple execution in my MATLAB command window to simplify what I want to get as output.
m=[4,12;6,8]
m =
4 12
6 8
max(m)
ans = 6 12
abs(m/max(m))
ans =
0.9333
0.7333
I am stuck with this problem for a long time. Please help.
A * C.asDiagonal().inverse()? Actually, I don't know what yourabsmeans, so this is just a random suggestion, probably wrong. - Marc Glisse