This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[SOLVED] center a matrix/vector - how to do this in an elegant way?

Tags: None
(comma "," separated)
HWJ
Registered Member
Posts
18
Karma
0
Hi,

the code at the end gives very strange error messages (at least for beginners)

How to implement the Matlab/Scilab notation

A= 2*(A-0.5)

in an elegant way.

I tried (failed miserably)

#include
using std::cout; using std::endl;

#include
using std::log; using std::sqrt;

#include
// import most common Eigen types
USING_PART_OF_NAMESPACE_EIGEN

int main() {
int N=5;
MatrixXd A = MatrixXd::Random(N,N);
A= 2*(A.cwise()-0.5); // transform matrix elements to be in [-1,1)
cout << "A=n" << A << endl;
}

Thanks for a hint,
Helmut.


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell