Though I would use Jitse's method as well, to give you another choice, here is a solution that is a bit more verbose and may show better where the parts go:
Eigen::MatrixXd newC(C.rows()+1, C.cols()+1);
newC.topRows<1>() = v.transpose();
newC.leftCols<1>() = v;
newC.bottomRightCorner(C.rows(),C.cols()) = C;
C.swap(newC)
Note that this assigns the top left element twice; if you don't want that, replace the third line with this ugly one:
newC.topRows<1>().tail(v.size()-1) = v.transpose().tail(v.size()-1);
As a final note as to why we don't use resize
: it always throws away your matrix content (even when shrinking a matrix), except when the number of elements stays exactly the same, i.e. when you resize an MxN
matrix to size (M*k)x(N/k)
.