each diagonal of a matrix
1 次查看(过去 30 天)
显示 更早的评论
.
i want sum diagonal matrix like this pic. please help me
0 个评论
采纳的回答
Star Strider
2018-4-23
Try this:
A = [1 2 3; 4 5 6; 7 8 9];
Af = fliplr(A); % Flip Matrix
ND = size(A,1)-1; % Number of Diagonals
D = ND:-1:-ND; % Diagonal Offset Vector
for k = 1:numel(D)
Dsum(k) = sum(diag(Af,D(k))); % Sum Each Diagonal
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!