changing diagional values with different values
显示 更早的评论
Hello,
Is there any way to do the following:
let assume this is my matrix (MX1):
x1 8 4 0
4 x2 0 9
1 0 x3 3
0 3 0 x4
what I'm trying to do is the followin:
I should calculate each "x", where x = the summation of the values in the same row. for Exp: X1 = 8+4+0. [are there any way to automate this calculation?]
My idea is changing the x's diagonal to zeros to get the summation from, where the x will be zero. [I know how to do it]
then, generating a duplicated matrix and copy the calculated diagonal to the new matrix. [Is that possible ?] *this is must be automated because my matrix is 98*98
Thanks
采纳的回答
更多回答(1 个)
Fangjun Jiang
2019-3-21
n=5;
a=magic(n);
b=a;
index=sub2ind(size(a),1:n,1:n);
b(index)=0;
s=sum(b,2);
b(index)=s;
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!