each diagonal of a matrix

1 次查看(过去 30 天)
.
i want sum diagonal matrix like this pic. please help me

采纳的回答

Star Strider
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 CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by