each diagonal of a matrix
1 view (last 30 days)
Show older comments
.
i want sum diagonal matrix like this pic. please help me
0 Comments
Accepted Answer
Star Strider
on 23 Apr 2018
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
2 Comments
More Answers (0)
See Also
Categories
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!