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

kelalaka
  • 5,064
  • 5
  • 27
  • 44
user189035
  • 5,589
  • 13
  • 52
  • 112

1 Answers1

15

You should use:

U.row(p-1).setZero();
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
  • One more question: how can I do this directly? --e.g. solved.eigenvectors().row(p-1).setZero(); – user189035 Mar 14 '14 at 10:34
  • 1
    @user189035 You cannot do this as [`eigenvectors()`](http://eigen.tuxfamily.org/dox/classEigen_1_1EigenSolver.html#a3236af3afbc89241aaed4fc868aa8435) returns a constant. – herohuyongtao Mar 14 '14 at 11:22