c++ - Eigen Matrix Library index operation -


say have

  eigen::vectorxd r = eigen::vectorxd::random(10);  

now want following:

  double lb1(-0.1);   double ub1(0.1);   double v(5.);    for(int =0;i<10;i++)       if( (lb1 < r[i]) && (r[i]<ub1))             r[i] = v; 

there many non overlapping (lb1,ub1) , many "v". there easy elegant way perform computation without writing 2 loops (i have matlab kind of operation in mind)

thanks in advance help.

you use .select()

r = (r.array() > lb1 && r.array() < ub1).select(v, r); 

Comments