I've got a lower triangular MatrixXd and I want to copy its lower values to the upper side as it'll become a symmetric matrix. How can I do it?
So far I've done:
MatrixXd m(n,n);
.....
//do something with m
for(j=0; j < n; j++)
{
for(i=0; i<j; i++)
{
m(i,j) = m(j,i);
}
}
Is there a fastest way to do it? I was thinking of some internal method that is able to "copy" the lower triangular matrix to the upper.
Say I've got this matrix, we call m
:
1 2 3
4 5 6
7 8 9
what I need to obtain in m
is :
1 4 7
4 5 8
7 8 9
I also know you can get the upper or the lower part of the matrix to do something:
MatrixXd m1(n,n);
m1 = m.triangularView<Eigen::Upper>();
cout << m1 <<endl;
1 2 3
0 5 6
0 0 9
But I can't yet get what I want...
m[j][i] = m[i][j]
? – Musculari < j
(and noti = n
). Not a significant speedup I'm afraid, though. – Muscular