MATLAB: Flip half of matrix over the diagonal to make a symmetric matrix

diagonalflipmatrix

Dear all, If I have a half of a matrix, e.g
1
2 3
4 5 6
7 8 9 10
...
I want to flip it over the diagonal to make a symmetric matrix:
1 2 4 7
2 3 5 8
4 5 6 9
7 8 9 10
Please help. Thanks

Best Answer

A=[1 0 0 0
2 3 0 0
4 5 6 0
7 8 9 10]
[n,m]=size(A);
B=A'+A
B(1:n+1:end)=diag(A)