How to copy all elements diagonally below the diagonal in Matlab?

I want to copy all the elements above the diagonal (not diagonal) under the diagonal without using any cycle or at minimal cost. So, after copying, the matrix will become a symmetric matrix:
i.e. for all i, j: A(i,j)=A(j,i).

Thank.

0
source share
1 answer

Use the command triu:

>> symMat = triu( A, 0 ) + triu( A, 1 ).';

This command will leave the diagonal Aunchanged.

+7
source

Source: https://habr.com/ru/post/1795004/


All Articles