4

Suppose I have a matrix A which is n x n matrix and I have a vector b which is n x 1 vector and I want to calculate the following implementation in Eigen library.

bsxfun(@rdivide, A, b)

How can I apply it Eigen ?

erogol
  • 13,156
  • 33
  • 101
  • 155
  • 2
    Scroll down to *Broadcasting*: http://eigen.tuxfamily.org/dox-devel/group__TutorialReductionsVisitorsBroadcasting.html – Dan Aug 23 '13 at 12:59

1 Answers1

2

How about this one:

Eigen::MatrixXf A(n,n);
Eigen::VectorXf b(n);

A.cwiseQuotient( b.replicate(1,A.cols()) )

Here is one without replication, equivalent to bsxfun in MATLAB:

A.array().colwise() / b.array()
Amro
  • 123,847
  • 25
  • 243
  • 454