a=b-diag(diag(b))
设矩阵为A
A-diag(diag(A))即可
A =
0.9501 0.7621 0.6154 0.4057 0.0579
0.2311 0.4565 0.7919 0.9355 0.3529
0.6068 0.0185 0.9218 0.9169 0.8132
0.4860 0.8214 0.7382 0.4103 0.0099
0.8913 0.4447 0.1763 0.8936 0.1389
A-diag(diag(A))
ans =
0 0.7621 0.6154 0.4057 0.0579
0.2311 0 0.7919 0.9355 0.3529
0.6068 0.0185 0 0.9169 0.8132
0.4860 0.8214 0.7382 0 0.0099
0.8913 0.4447 0.1763 0.8936 0