setting a row of a matrix to 0, in eigen
Asked Answered
M

1

8

kind of strange:

I'm trying to set a full row of a matrix to 0 and neither of the four obvious constructs in eigen would compile:

//U is a p by p matrix. I wanna set its last column to 0.0f
U=solved.eigenvectors();   

U.row(p-1).array()=0;              //don't compile
U.row(p-1).setZero(1,p);           //don't compile
U.row(p-1).array().setZero(p);     //don't compile
U.bottomRows(1).setZero(p);        //don't compile

I also tried other variations on these themes but neither passed the compiler

Milicent answered 13/3, 2014 at 18:21 Comment(0)
G
15

You should use:

U.row(p-1).setZero();
Galen answered 13/3, 2014 at 18:25 Comment(2)
One more question: how can I do this directly? --e.g. solved.eigenvectors().row(p-1).setZero();Milicent
@Milicent You cannot do this as eigenvectors() returns a constant.Galen

© 2022 - 2024 — McMap. All rights reserved.