MATLAB: How to convert row and column vectors of a symmetric matrix to zero if diagonal value is zero

diagonalMATLAB

I have symmetric matrices of large size. I need to ensure that if there are any zeros on the main diagonal, then their corresponding row and column vectors are also set to zero. Please help.

Best Answer

This would do it without loop- index=find(diag(your_matrix)==0); your_matrix(index,:)=0; your_matrix(:,index)=0;