How to set the new values to zero after resizing a matrix? It is really weird that after resizing the matrix, the new values are set to trash values instead of at least set to zero.
N = 0;
Eigen::MatrixXd CO;
CO.setZero(3+3*N, 3+3*N);
std::cout << CO << std::endl << std::endl;
Nt = 1;
CO.conservativeResize(3+3*Nt,3+3*Nt);
std::cout << CO << std::endl << std::endl;
The result
I've solved the problem by using conservativeResizeLike()
int Nt = 0;
Eigen::MatrixXd CO;
CO.setOnes(3+3*Nt, 3+3*Nt);
std::cout << CO << std::endl << std::endl;
Nt = 1;
CO.conservativeResizeLike(Eigen::MatrixXd::Zero(3+3*Nt,3+3*Nt));
std::cout << CO << std::endl << std::endl;
The result
Also, I found out you can set them as ones Eigen::MatrixXd::Ones(3+3*Nt,3+3*Nt)
or identity Eigen::MatrixXd::Identity(3+3*Nt,3+3*Nt)
For Identity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With