I have two Eigen::MatrixXd
and they always have a single row. The input matrix is A
and I want to copy this matrix into another matrix B
, but the number of columns between the matrices can be different.
Following is an example:
A
0.5
And I need to create a B
matrix of 1 rows and 4 columns, so that it will be:
B
0.5 0.5 0.5 0.5
But if A
is:
A
1 0.5
Then B
will be
B
1 0.5 1 0.5
How can I do?
You can replicate a matrix by using the (wait for it) replicate
function. The first parameter is how many times to repeat the rows, the second is the number of times to repeat the columns.
#include <iostream>
#include <Eigen/Core>
int main()
{
Eigen::MatrixXd a(1, 2), b;
a << 1, 0.5;
b = a.replicate(1, 2);
std::cout << a << "\nbecomes:\n" << b << std::endl;
return 0;
}
gives
1 0.5
becomes:
1 0.5 1 0.5
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