Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

1 solution

You need to understand the math behind the matrix:
How to Divide Matrices (with Pictures) - wikiHow[^]

You cant divide one matrix on another matrix directly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900